定义:可以控制两张图片之间的淡入淡出效果(不超过两张),通过startTransition()执行,reverseTransition()撤销.

用法:

<?xml version="1.0" encoding="utf-8"?><transitionxmlns:android="http://schemas.android.com/apk/res/android" >    <item        android:drawable="@[package:]drawable/drawable_resource"        android:id="@[+][package:]id/resource_name"        android:top="dimension"        android:right="dimension"        android:bottom="dimension"        android:left="dimension" /></transition>

属性 作用
android:drawable 图片资源
android:top、android:right、android:bottom、android:left 距离各边的距离

官方示例:

XML file saved at res/drawable/transition.xml:<?xml version="1.0" encoding="utf-8"?><transition xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/on" />    <item android:drawable="@drawable/off" /></transition>This layout XML applies the drawable to a View:<ImageButton    android:id="@+id/button"    android:layout_height="wrap_content"    android:layout_width="wrap_content"    android:src="@drawable/transition" />And the following code performs a 500ms transition from the first item to the second:ImageButton button = (ImageButton) findViewById(R.id.button);TransitionDrawable drawable = (TransitionDrawable) button.getDrawable();drawable.startTransition(500);


效果:

xml文件:
<?xml version="1.0" encoding="utf-8"?><transition xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@mipmap/reasource_drawable_mn"/>    <item android:drawable="@mipmap/reasource_drawable_mn2"/></transition>

Activity中:
final TransitionDrawable drawable = (TransitionDrawable) img_transition.getDrawable();        btn_startTransition.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                drawable.startTransition(2000);            }        });        btn_reverseTransition.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                drawable.reverseTransition(2000);            }        });

效果:




更多相关文章

  1. 把TextView中的文字添加阴影效果及Style的使用
  2. Android Textview 阴影效果
  3. android 图片自动切换
  4. android 5.0以上版本控件点击 水波纹效果
  5. 【转】android 图片自动切换
  6. android 背景图片
  7. android图片切换ImageSwichter的动画切换效果
  8. 跑马灯效果:

随机推荐

  1. android WebView中js的alert()失效
  2. Android NDK For Linux安装配置指南
  3. In android studio,cannot load 2 facets
  4. 关于Android屏幕密度与分辨率
  5. Android -- 多页滑动(ViewPager)
  6. Android自定义dialog简单实现方法
  7. Android(安卓)View的点击事件分发机制
  8. android 数据存储总结及各种存储方式
  9. Android(安卓)获取唯一机器码的代码
  10. Android中获取设备的IP