这篇文章将为大家详细讲解有关Android中如何使用Drawbl资源,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
Drawble是Android应用中使用最灵活,也是最广泛的资源,不仅可以直接使用".png",".jpg",".9.png"等图片做为资源,也可以直接使用多种XML文件作为资源。只要一份XML文件可以被系统编译成Drawble子类的对象,那么这份XML文件就可以作为Drawble资源
Drawble下图片资源
最简单的资源,吧".png",".jpg",".9.png"等格式放入/res/drawble-xxx目录下,Android应用在编译应用时会自佛呢及时加载图片,并在R清单类中生成该资源的索引
Drawble下StateListDrawble资源
用于组织多个Drawble对象。当使用StateListDrawble作为目标组件的背景,背景图片时,StateListDrawble对象所心事的Drawble对象会随着目标组件的改变而自动切换
运用场景:高亮显示文本框
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 指定获得焦点时的颜色 -->
<item android:state_focused="true"
android:color="#f44"/>
<!-- 指定失去焦点时的颜色 -->
<item android:state_focused="false"
android:color="#ccf"/>
</selector>
Drawble下LayerDrawble资源
和StateListDrawble有点类似,LayerDrawble也可以包含一个Drawble数组,因此字体将会按照这些Drawble对象的数组顺序来绘制它们,索引最大的Drawble对象将会被绘制在最上面
运用场景:定制拖动条外观
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 定义轨道的背景 -->
<item android:id="@android:id/background"
android:drawable="@drawable/grow" />
<!-- 定义轨道上已完成部分的外观-->
<item android:id="@android:id/progress"
android:drawable="@drawable/ok" />
</layer-list>
Drawble下ShapeDrawble资源
用于定义一个基本的几何图形(例如:圆形,矩形,线性),定义ShapeDrawble的XML文件的跟元素的<shape...>
运用场景:椭圆形的文本框
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 设置填充颜色 -->
<solid android:color="#fff"/>
<!-- 设置四周的内边距 -->
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<!-- 设置边框 -->
<stroke android:width="3dip" android:color="#ff0" />
</shape>
Drawble下ClipDrawble资源
代表从全位图上街区的一个图片的片段,在XML中使用<clip..>开头
运用场景:慢慢展开的风景
<?xml version="1.0" encoding="UTF-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/shuangta"
android:clipOrientation="horizontal"
android:gravity="center">
</clip>
Drawble下AnimationDrawble资源
代表一个动画,既支持传统的逐帧动画,也支持通过平移、变换计算出来的补间动画。
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:duration="5000">
<!-- 定义缩放变换 -->
<scale android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="0.6"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:duration="2000"/>
<!-- 定义位移变换 -->
<translate android:fromXDelta="10"
android:toXDelta="130"
android:fromYDelta="30"
android:toYDelta="-80"
android:duration="2000"/>
</set>
关于Android中如何使用Drawbl资源就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:http://blog.itpub.net/69917874/viewspace-2694709/