Android资源之Drawable介绍(二)

接上篇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等一系列相关资料,也是今天在找相关资料时发现的,资料很全面哦。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值