xml布局文件
https://blog.csdn.net/u013475386/article/details/44339035
gravity写在容器中中
layout_gravity写在控件中
layout_margriLeft距离右边框
自定义ui形状的XML文件
用XML文件去描绘一个图形形状
首先在drawable里面创建一个XML文件
然后用shape标签去描述图片的形状
例如:
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <solid android:color="#ffffffff" />
- <corners android:radius="10dp" />
- <padding
- android:bottom="10dp"
- android:left="5dp"
- android:right="5dp"
- android:top="5dp" />
- <stroke
- android:width="2dp"
- android:color="#ff00bbe8" >
- </stroke>
- </shape>
描绘完了之后就在layout布局文件中去调用这个图片
如下:
- <EditText
- android:id="@+id/mText"
- android:layout_width="fill_parent"
- android:layout_height="100px"
- android:background="@drawable/shape"
- android:textColor="#aa000000"
- android:textSize="20dp"
- android:gravity="top"
- android:layout_margin="3dp"
- android:paddingLeft="10dp"
- android:paddingRight="10dp"/>



shape还可以嵌入到selector里面去使用,就是作为selector的子标签
如下所示
- <?xml version="1.0" encoding="utf-8"?>
- <selector
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_pressed="true" >
- <shape>
- <!-- 渐变 -->
- <gradient
- android:startColor="#ff8c00"
- android:endColor="#FFFFFF"
- android:type="radial"
- android:gradientRadius="50" />
- <!-- 描边 -->
- <stroke
- android:width="2dp"
- android:color="#dcdcdc"
- android:dashWidth="5dp"
- android:dashGap="3dp" />
- <!-- 圆角 -->
- <corners
- android:radius="2dp" />
- <padding
- android:left="10dp"
- android:top="10dp"
- android:right="10dp"
- android:bottom="10dp" />
- </shape>
- </item>
- <item android:state_focused="true" >
- <shape>
- <gradient
- android:startColor="#ffc2b7"
- android:endColor="#ffc2b7"
- android:angle="270" />
- <stroke
- android:width="2dp"
- android:color="#dcdcdc" />
- <corners
- android:radius="2dp" />
- <padding
- android:left="10dp"
- android:top="10dp"
- android:right="10dp"
- android:bottom="10dp" />
- </shape>
- </item>
- <item>
- <shape>
- <solid android:color="#ff9d77"/>
- <stroke
- android:width="2dp"
- android:color="#fad3cf" />
- <corners
- android:topRightRadius="5dp"
- android:bottomLeftRadius="5dp"
- android:topLeftRadius="0dp"
- android:bottomRightRadius="0dp"
- />
- <padding
- android:left="10dp"
- android:top="10dp"
- android:right="10dp"
- android:bottom="10dp" />
- </shape>
- </item>
- </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布局文件的更多相关文章
- 使用XML布局文件和Java代码混合控制UI界面
完全使用Java代码来控制UI界面不仅烦琐.而且不利于解耦:而完全利用XML布局文件来控制UI界面虽然方便.便捷,但难免有失灵活.因此有些时候,可能需要混合使用XML布局文件和代码来控制UI界面. 当 ...
- Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析
转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PAREN ...
- Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout
一.布局文件part.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- XML布局文件于Java代码使用问题
2013-9-21 问题一.不同的XML文件中相同类型的控件id相同,那么将这些不同的布局xml组合在一个大的布局中,如何解决相同id问题 ? 解决办法: 不同的布局文件XML要组合成一个新的大布局, ...
- Android中将xml布局文件转化为View树的过程分析(下)-- LayoutInflater源码分析
在Android开发中为了inflate一个布局文件,大体有2种方式,如下所示: // 1. get a instance of LayoutInflater, then do whatever yo ...
- Android中将xml布局文件转化为View树的过程分析(上)
有好几周没写东西了,一方面是因为前几个周末都有些事情,另外也是因为没能找到好的写作方向,或者说有些话题 值得分享.写作,可是自己积累还不够,没办法只好闷头继续研究了.这段时间一边在写代码,一边也在想A ...
- Activity 怎样获得另一个xml布局文件的控件
两个布局文件,一个main.xml,一个main2.xml,一个MActivity,在MActivity的onCreate()里设置的是setContentView(R.layout.main).现在 ...
- Android studio3.1的XML布局文件没有自动提示不全代码功能
将studio从2.3升级到3.1,打开后发现布局文件没有代码提示 尝试了网上一些解决方法,但发现并不是平时所说的省电模式开关的问题,也尝试了删除idea和iml文件后rebuild的方法,无效 然后 ...
- Android Fragment之间的通信(用fragment替换掉XML布局文件中的一个线性布局)
1.XML布局 (1)主界面 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...
随机推荐
- mini2440 最小根文件系统制作和nfs启动
mini2440 内核启动后,可以用busybox制作一个简单的根文件系统并用nfs来启动该文件系统 启动mini2440, 按任意键进入uboot,按q键进入uboot命令行: 执行以下命令: se ...
- Python多人聊天室
一.目的 以实现小项目的方式,来巩固之前学过的Python基本语法以及相关的知识. 二.相关技术: 1.wxpython GUI编程 2.网络编程 3.多线程编程 4.数据库编程 5.简单的将数据导出 ...
- Codeforces - 828C String Reconstruction —— 并查集find()函数
题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...
- JavaScript中双叹号(!!)作用示例介绍
http://www.jb51.net/article/48881.htm 经常看到这样的例子: var a: var b=!!a; a默认是undefined.!a是true,!!a则是false, ...
- Object.is() Pollyfill
if (!Object.is) { Object.is = function(x, y) { // SameValue algorithm if (x === y) { // Steps 1-5, 7 ...
- php设计模式课程---5、责任链模式是什么
php设计模式课程---5.责任链模式是什么 一.总结 一句话总结: 自己权限不够,就交给上级处理 1.选择结构怎么做到面向对象开闭原则? 也就是说if,都可以用接口的实现来实现,这样就避免了更新的时 ...
- laravel基础课程---5、路由复习(路由作用)
laravel基础课程---5.路由复习(路由作用) 一.总结 一句话总结: 有利于百度收录,及SEO优化 1.路由书写 (D:\laravel\yzmedu\yzm2\routes\web.php) ...
- 分享知识-快乐自己:Struts2中 获取 Request和Session
目录结构: POM: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEnco ...
- Visual Studio 2012 与此版本的 Windows 不兼容 解决
警告: [Window Title] 程序兼容性助手[Main Instruction] 此程序存在已知的兼容性问题[Expanded Information] Visual Studio 2012 ...
- ACM学习历程—HDU1717 小数化分数2(gcd)
Description Ray 在数学课上听老师说,任何小数都能表示成分数的形式,他开始了化了起来,很快他就完成了,但他又想到一个问题,如何把一个循环小数化成分数呢? 请你写一个程序不但可以将普通小数 ...