https://blog.csdn.net/u013475386/article/details/44339035

gravity写在容器中中

layout_gravity写在控件中

layout_margriLeft距离右边框

自定义ui形状的XML文件

用XML文件去描绘一个图形形状

首先在drawable里面创建一个XML文件

然后用shape标签去描述图片的形状

例如:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <solid android:color="#ffffffff" />
  4. <corners android:radius="10dp" />
  5. <padding
  6. android:bottom="10dp"
  7. android:left="5dp"
  8. android:right="5dp"
  9. android:top="5dp" />
  10. <stroke
  11. android:width="2dp"
  12. android:color="#ff00bbe8" >
  13. </stroke>
  14. </shape>

描绘完了之后就在layout布局文件中去调用这个图片

如下:

  1. <EditText
  2. android:id="@+id/mText"
  3. android:layout_width="fill_parent"
  4. android:layout_height="100px"
  5. android:background="@drawable/shape"
  6. android:textColor="#aa000000"
  7. android:textSize="20dp"
  8. android:gravity="top"
  9. android:layout_margin="3dp"
  10. android:paddingLeft="10dp"
  11. android:paddingRight="10dp"/>

shape还可以嵌入到selector里面去使用,就是作为selector的子标签

如下所示

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector
  3. xmlns:android="http://schemas.android.com/apk/res/android">
  4. <item android:state_pressed="true" >
  5. <shape>
  6. <!-- 渐变 -->
  7. <gradient
  8. android:startColor="#ff8c00"
  9. android:endColor="#FFFFFF"
  10. android:type="radial"
  11. android:gradientRadius="50" />
  12. <!-- 描边 -->
  13. <stroke
  14. android:width="2dp"
  15. android:color="#dcdcdc"
  16. android:dashWidth="5dp"
  17. android:dashGap="3dp" />
  18. <!-- 圆角 -->
  19. <corners
  20. android:radius="2dp" />
  21. <padding
  22. android:left="10dp"
  23. android:top="10dp"
  24. android:right="10dp"
  25. android:bottom="10dp" />
  26. </shape>
  27. </item>
  28. <item android:state_focused="true" >
  29. <shape>
  30. <gradient
  31. android:startColor="#ffc2b7"
  32. android:endColor="#ffc2b7"
  33. android:angle="270" />
  34. <stroke
  35. android:width="2dp"
  36. android:color="#dcdcdc" />
  37. <corners
  38. android:radius="2dp" />
  39. <padding
  40. android:left="10dp"
  41. android:top="10dp"
  42. android:right="10dp"
  43. android:bottom="10dp" />
  44. </shape>
  45. </item>
  46. <item>
  47. <shape>
  48. <solid android:color="#ff9d77"/>
  49. <stroke
  50. android:width="2dp"
  51. android:color="#fad3cf" />
  52. <corners
  53. android:topRightRadius="5dp"
  54. android:bottomLeftRadius="5dp"
  55. android:topLeftRadius="0dp"
  56. android:bottomRightRadius="0dp"
  57. />
  58. <padding
  59. android:left="10dp"
  60. android:top="10dp"
  61. android:right="10dp"
  62. android:bottom="10dp" />
  63. </shape>
  64. </item>
  65. </selector>

这里涉及了很多shape的属性问题

这些属性都是不难的,应该可以看得懂的,

padding:间隔

solid:实心,就是填充的意思
android:color指定填充的颜色

gradient:渐变
android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。
另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。

stroke:描边
android:width="2dp" 描边的宽度,android:color 描边的颜色。
我们还可以把描边弄成虚线的形式,设置方式为:
android:dashWidth="5dp" 
android:dashGap="3dp"
其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。

corners:圆角
android:radius为角的弧度,值越大角越圆。
我们还可以把四个角设定成不同的角度,方法为:
<corners 
        android:topRightRadius="20dp"    右上角
        android:bottomLeftRadius="20dp"    右下角
        android:topLeftRadius="1dp"    左上角
        android:bottomRightRadius="0dp"    左下角
 />

xml布局文件的更多相关文章

  1. 使用XML布局文件和Java代码混合控制UI界面

    完全使用Java代码来控制UI界面不仅烦琐.而且不利于解耦:而完全利用XML布局文件来控制UI界面虽然方便.便捷,但难免有失灵活.因此有些时候,可能需要混合使用XML布局文件和代码来控制UI界面. 当 ...

  2. Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析

    转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PAREN ...

  3. Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout

    一.布局文件part.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  4. XML布局文件于Java代码使用问题

    2013-9-21 问题一.不同的XML文件中相同类型的控件id相同,那么将这些不同的布局xml组合在一个大的布局中,如何解决相同id问题 ? 解决办法: 不同的布局文件XML要组合成一个新的大布局, ...

  5. Android中将xml布局文件转化为View树的过程分析(下)-- LayoutInflater源码分析

    在Android开发中为了inflate一个布局文件,大体有2种方式,如下所示: // 1. get a instance of LayoutInflater, then do whatever yo ...

  6. Android中将xml布局文件转化为View树的过程分析(上)

    有好几周没写东西了,一方面是因为前几个周末都有些事情,另外也是因为没能找到好的写作方向,或者说有些话题 值得分享.写作,可是自己积累还不够,没办法只好闷头继续研究了.这段时间一边在写代码,一边也在想A ...

  7. Activity 怎样获得另一个xml布局文件的控件

    两个布局文件,一个main.xml,一个main2.xml,一个MActivity,在MActivity的onCreate()里设置的是setContentView(R.layout.main).现在 ...

  8. Android studio3.1的XML布局文件没有自动提示不全代码功能

    将studio从2.3升级到3.1,打开后发现布局文件没有代码提示 尝试了网上一些解决方法,但发现并不是平时所说的省电模式开关的问题,也尝试了删除idea和iml文件后rebuild的方法,无效 然后 ...

  9. Android Fragment之间的通信(用fragment替换掉XML布局文件中的一个线性布局)

    1.XML布局 (1)主界面 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...

随机推荐

  1. android的GPS代码分析JNI如何HAL之间如何设置回调函数【转】

    本文转载自:http://blog.csdn.net/kmesg/article/details/6531577 本文只关注JNI和HAL的接口部分 在jni的android_location_Gps ...

  2. SecureCRT连接Ubuntu失败(远程系统拒绝访问)

    SecureCRT连接Ubuntu失败,长时间的重新连接,连接不了. Ubuntu默认未安装ssh远程加密连接服务. 使用命令,安装即可. sudo apt-get install openssh-s ...

  3. macd背离的级别

    1分钟的背离可以忽略不看. 5分钟的背离可以预测未来5-6个小时的股价. 15分钟级别的背离可以预测未来24小时之内的股价. 30分钟级别的背离可以做中线. 周线背离可以影响1-2年的股价. 背离级别 ...

  4. 使用C++模拟C#的委托机制

    1. [代码][C/C++]代码 //Event.h  #ifndef _EVENT_H_#define _EVENT_H_class EmptyObject {};template<typen ...

  5. Eclipse中导入github上的项目

    Eclipse中导入github上的项目 转载至: http://blog.csdn.net/hil2000/article/details/8566456 1.首先在github.com上申请一个账 ...

  6. 「LOJ#10056」「一本通 2.3 练习 5」The XOR-longest Path (Trie

    #10056. 「一本通 2.3 练习 5」The XOR-longest Path 题目描述 原题来自:POJ 3764 给定一棵 nnn 个点的带权树,求树上最长的异或和路径. 输入格式 第一行一 ...

  7. CodeForces - 123E Maze

    http://codeforces.com/problemset/problem/123/E 题目翻译:(翻译来自: http://www.cogs.pw/cogs/problem/problem.p ...

  8. Django 发送email配置详解及各种错误类型

    跟随Django Book的内容发送邮件不成功,总结一下需要配置好settings.py文件,还要注意一些细节. 1.在settings文件最后添加以下内容,缺一不可! EMAIL_HOST= 'sm ...

  9. The Review Plan I-禁位排列和容斥原理

    The Review Plan I Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB   64-bit integer ...

  10. 搭建基于Nagios的监控系统——之监控远程Linux服务器

    上一篇介绍了如何安装Nagios Core,这一篇跟大家分享一下如何将一台远程的Linux服务器加入纳入监控范围. 第一部分:在远程Linux上安装Nagios Plugins和NRPE   第一步: ...