Android应用中res/drawable文件夹下定义的xml文件内容详解(一)
来源:互联网 发布:安卓小说阅读器源码 编辑:程序博客网 时间:2024/05/01 09:24
drawable文件夹下定义的xml有哪些作用?
首先,看看有哪些标签可以使用,一共有10类,我使用
Eclipse:Version: Luna Service Release 1a (4.4.1)。在xml中Ctrl+/可以看到以下内容。
还有一类layer-list,上图没有显示出来,暂时还不知道为什么,这个标签用于图形叠加。
从最常用和最熟悉的说起:
1、shape标签
- 通常用于自定义控件背景,圆角、渐变、填充等静态背景效果。可以这种方法定义的图形,尽量选用这种方式,可以减小apk包大小。
摘抄:http://blog.csdn.net/ekeuy/article/details/12349853
2、使用示例
- shape文件中stroke使用效果,定义了一个红色边框
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- stroke就是定义的边框,这里指定边框宽度为1dip, --> <!-- 另外我们可以指定每个, --> <stroke android:width="1dip" android:color="@color/red" /></shape>
- 给TextView定义一个灰色背景,如果是纯色可以直接color,这里还是一试。另外试下shape文件中padding的用法。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- solid就一个颜色属性, --> <solid android:color="@color/gray" /> <stroke android:width="2dp" android:color="@color/red" /> <!-- padding的作用时图形边框距内容的距离,padding值不包含边框宽度;这个属性应该用得比较少,因为控件本身就有类似控制属性。 android:left 整型 左内边框距内容的距离 android:top 整型 上内边框距内容的距离 android:right 整型 右内边距 android:bottom 整型 下内边距 --> <padding android:left="20dp" /></shape>
- 3、给TextView定义一个白色背景,灰色圆角边框。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 这里灰色边框 --> <stroke android:width="1dp" android:color="@color/grey" /> <!-- 每个角半径,数字越大,角就越圆 --> <corners android:radius="10dp" /> <!-- 设置了左边距 --> <padding android:left="50dp"/></shape>
- 4、给按钮定义一个从上到下渐变的背景色。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="10dp" /> <padding android:left="10dp" android:right="10dp" /> <gradient android:angle="90" android:endColor="@color/backColor" android:startColor="@color/red" /></shape>
- 5、给按钮定义一个从上到下渐变的背景色并且点击时可以变化,。需要再定义一个点击时显示的背景色,还要用到selector
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <!--默认时显示背景--> <item android:drawable="@drawable/shape_file_use_demo_4"/> <!--点击时显示背景--> <item android:drawable="@drawable/shape_file_use_demo_5" android:state_pressed="true"/></selector>
- shape_file_use_demo_5.xml
正常显示以第4示例中的背景来显示,点击时的背景人是调换了开始和结束的位置。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="10dp" /> <padding android:left="10dp" android:right="10dp" /> <gradient android:angle="90" android:endColor="@color/red" android:startColor="@color/backColor" /></shape>
0 0
- Android应用中res/drawable文件夹下定义的xml文件内容详解(一)
- Android应用中res/drawable文件夹下定义的xml文件内容(二)selector
- Android中自定义属性的使用------res/values文件下定义一个attrs.xml
- Android中自定义属性的使用------res/values文件下定义一个attrs.xml
- android 自定义属性的使用一、在res/values文件下定义一个attrs.xml文件,代码如下
- 关于android中drawable文件夹下各类xml样式文件的使用详解
- 关于android中drawable文件夹下各类xml样式文件的使用详解
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)
- Android资源文件res的使用详解(strings,layout,drawable,arrays,动画等)
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)
- Android资源文件res的使用详解(strings,layout,drawable,arrays等)
- Android studio读取res文件夹下的xml文件(备忘)
- 关于android的res里面的各个drawable文件夹
- Android res下三个drawable文件夹的用途
- 为什么线性筛欧拉函数i%prime[j]==0的时候phi[i*prime[j]]=phi[i]*prime[j]
- ArcGis把jpg、png格式地图图片转换为tif格式
- zsh不兼容的坑-zsh:no matches found
- 产生死锁的必要条件
- Python——13定制类
- Android应用中res/drawable文件夹下定义的xml文件内容详解(一)
- 仿宝宝树孕育的圆形ListView的实现
- 锤子剪刀布
- Android开发笔记之RecycleView加载不同item布局的实现
- 位运算的特殊用途
- Wordpress条件标签的使用
- Bestcoder round#85 解题报告
- C#控制台 VS2015使用技巧 生成类图的步骤
- CDOJ 1144 Big Brother