接上篇Drawable介绍Android资源之Drawable介绍(一)。
–TransitionDrawable——–
TransitionDrawable是LayerDrawable的子类,是一个特殊的Drawable对象,可以实现两个drawable资源之间淡入淡出的动画效果。定义xml资源transition_drawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@mipmap/ic_launcher"
android:left="20dp"
android:top="10dp" /><!--每个<item>代表一个drawable资源-->
<item
android:drawable="@mipmap/test_iv"
android:left="20dp"
android:top="10dp" />
</transition>
<!--
android:drawable——引用的Drawable资源。
android:top——与顶部的距离
android:right——与右边的距离
android:bottom——与下边的距离
android:left——与左边的距离-->
代码中使用:
<ImageView
android:id="@+id/test_iv"
android:src="@drawable/transition_drawable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
ImageView iv=(ImageView)findViewById(R.id.test_iv);
TransitionDrawable drawable=(TransitionDrawable)iv.getDrawable;
drawble.setTransition(3000);
有TransitionDrawable,肯定也有ScaleDrawable,AlphaDrawable等 对应动画效果的Drawble。使用方法类似。
–InsetDrawable——–
InsetDrawable表示一个Drawable嵌入到另外一个Drawable内部,关且内部Drawable与外部Drawable之间有一定距离,比较像Drawable的Padding属性。定义inset_drawable.xml资源:
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@mipmap/test_iv"
android:insetBottom="20dp"
android:insetLeft="20dp"
android:insetRight="20dp"
android:insetTop="20dp"> <!-- android:inset="20dp"-->
</inset>
<!--
android:drawable——引用的Drawable资源。
android:insetTop——与顶部的距离
android:insetRight——与右边的距离
android:insetBottom——与下边的距离
android:insetLeft——与左边的距离
android:inset——设置左右上下的距离值
-->
–ClipDrawable——–
ClipDrawable是对图像资源Drawable进行剪切操作,通过控件剪切区域达到我们想要的剪切效果。通过setLevel(int level)方法来设置剪切区域。
level取值范围0-10000,0表示完全显示,10000表示完全不显示
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="horizontal"
android:drawable="@mipmap/ic_launcher"
android:gravity="center" />
<!--
android:drawable——表示该ClipDrawable引用的drawable资源。
android:clipOrientation——裁剪的方向。下面两种的数值之一: horizontal 水平方向裁剪/ vertical 垂直方向裁剪
android:gravity——指定从哪个地方裁剪。-->
代码中使用ClipDrawble:
ImageView iv=(ImageView)findViewById(R.id.test_iv);
ClipDrawable drawble=(ClipDrawable)iv.getDrawable();
drawable.setLevel(2000);//设置Level值。
推荐学习http://blog.csdn.net/lonelyroamer/article/details/8148147等一系列相关资料,也是今天在找相关资料时发现的,资料很全面哦。