Android Drawable Resources系列6:<transition>
来源:互联网 发布:算法及其描述 2 1 编辑:程序博客网 时间:2024/04/29 08:12
定义:可以控制两张图片之间的淡入淡出效果(不超过两张),通过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); } });
效果:
0 0
- Android Drawable Resources系列6:<transition>
- android drawable Transition Drawable
- Android Drawable Resources系列3:<layer-list>
- Android Drawable Resources系列4:<selector>
- Android Drawable Resources系列5:<level-list>
- Android Drawable Resources系列7:<inset>
- Android Drawable Resources系列8:<clip>
- Android Drawable Resources系列9:<scale>
- Android Drawable Resources系列10:<shape>
- Android Shape Drawable Resources
- Android Shape Drawable Resources
- android-Drawable Resources
- Android: Drawable Resources
- Android API Guides---Drawable Resources
- Android Drawable - Transition Drawable使用详解(附图)
- Android中的Drawable资源——Transition Drawable
- Android Drawable Resources系列1:Bitmap(dither图像抖动、tileMode平铺模式)
- Android Drawable Resources系列2:<nine-patch>标签、.9.png图片制作
- HZAU 1001 Handing Out Candies
- 使用HTML5本地储存localStorage
- Android MVP设计模式的理解
- JAVA敏捷开发环境搭建
- tsung
- Android Drawable Resources系列6:<transition>
- HZAUoj 1015: LCS
- Idea15下载Maven源码和文档
- 文章标题
- 理解JPA注解@GeneratedValue
- SharedPreferences工具类
- 今天开通博客
- hdu 2141 枚举后 二分查找
- javascript之debounce函数