Android开发之drawable文件夹下的各种XML标签的用法总结

2015-08-21 16:53 评论 0 条

animation-list:Android用animation-list实现逐帧播放动画的效果

<?xml version="1.0" encoding="utf-8"?>
<!--
根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
根标签下,通过item标签对动画中的每一个图片进行声明
android:duration 表示展示所用的该图片的时间长度
-->
<animation-list  xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot="true">
<item android:drawable="@drawable/icon1" android:duration="150"></item>
<item android:drawable="@drawable/icon2" android:duration="150"></item>
<item android:drawable="@drawable/icon3" android:duration="150"></item>
<item android:drawable="@drawable/icon4" android:duration="150"></item>
<item android:drawable="@drawable/icon5" android:duration="150"></item>
<item android:drawable="@drawable/icon6" android:duration="150"></item>
</animation-list>

bitmap:使用xml定义图片,为图片定义别名,还能够给bitmap定义一些其它属性,例如抖动、锯齿等

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@[package:]drawable/drawable_resource"
android:antialias=["true" | "false"]
android:dither=["true" | "false"]
android:filter=["true" | "false"]
android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |"fill_vertical" | "center_horizontal" | "fill_horizontal" |
"center" | "fill" | "clip_vertical" | "clip_horizontal"]
android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />

clip:具体怎么时候使用还没弄清楚,请指教

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android=http://schemas.android.com/apk/res/android
android:drawable="@drawable/ic_launcher"
android:clipOrientation="horizontal"
android:gravity="right" />
</clip>

color:设置对应的颜色值,搜集了常用的一些颜色值,方便使用

<?xml version="1.0" encoding="utf-8" ?>
<resources>
<color name="gold">#FFD700</color><!--金色 -->
<color name="pink">#FFC0CB</color><!--粉红色 -->
<color name="lightpink">#FFB6C1</color><!--亮粉红色 -->
<color name="orange">#FFA500</color><!--橙色 -->
<color name="lightsalmon">#FFA07A</color><!--亮肉色 -->
</resources>

corners:中文是“角”的意思,设置角的弧度等

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="20.0px" /><!--设置圆角弧度-->
<solid android:color="@color/red_light" /><!--设置当前固定的颜色-->
<padding<!--设置文本上下左右内边距-->
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>

gradient:中文意思为“渐变”,顾名思义改标签用于设置背景颜色的渐变

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#FFC0CB"<!--设置开始的颜色为粉红色-->
android:endColor="#696969"<!--设置结束的颜色为暗灰色-->
android:angle="45" /><!--angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。-->
</shape>
在需要的xml文件中调用即可:android:backgroud="drawable/你的文件的名字"

inset:表示一个drawable嵌入到另外一个drawable内部,并且在内部留一些间距,当控件需要的背景比实际的边框小的时候比较适合使用InsetDrawable。

<?xml version="1.0" encoding="utf-8"?>
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:insetTop="dimension"
android:insetRight="dimension"
android:insetBottom="dimension"
android:insetLeft="dimension" />

item:设定选项状态

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/shape_red_corners_button_pressed"
android:state_pressed="true"/>
<item
android:drawable="@drawable/shape_red_corners_button"
android:state_pressed="false"/>
</selector>

selector:颜色、图片选择器

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_red_corners_button_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/shape_red_corners_button" android:state_pressed="false"/>
</selector>

shape:下面xml名称为shape_red_corners_button_pressed,即是上面selector按下状态的引用

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="20.0px" /><!--设置圆角弧度-->
<solid android:color="@color/red_light" /><!--设置当前固定的颜色-->
<padding<!--设置文本上下左右内边距-->
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>

size设置大小

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"<!--oval是椭圆的-->
android:useLevel="false">
<solid
android:color="@color/red"/>
<stroke
android:width="1dp"
android:color="@color/white"/>
<size
android:width="20dp"
android:height="20dp"/>
</shape>

solid:中文是“实现,实体”的意思,下面xml名称为shape_red_corners_button,即是上面selector未按下状态的引用

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="20.0px" /><!--设置圆角弧度-->
<solid android:color="@color/red_dark" /><!--设置当前固定的颜色-->
<padding<!--设置文本上下左右内边距-->
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>

stroke:中文是“描边”的意思,大概是用来设置边框属性用的,但是在写的布局中使用看不到效果,先把代码粘出来

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="20.0px" />
<solid android:color="@color/red_light" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<stroke
android:width="1dp"
android:color="@color/black" /><!--另外两个属性android:dashWidth=""和android:dashGap=""-->
</shape>

当前文章价值7.07元,扫一扫支付后添加微信提供帮助!(如不能解决您的问题,可以申请退款)

你可能感兴趣的文章

来源:每日教程每日一例,深入学习实用技术教程,关注公众号TeachCourse
转载请注明出处: https://www.teachcourse.cn/358.html ,谢谢支持!

资源分享

分类:Android 标签:
静态代码块,非静态代码块和构造方法执行顺序 静态代码块,非静态代码块和构造
Android系统搜索框架实战:提示最近查询内容 Android系统搜索框架实战:提示
Android Studio如何快速更改目录结构和包名? Android Studio如何快速更改目
拨打电话小应用Demo 拨打电话小应用Demo