Android中的Drawable资源——Transition Drawable
16lz
2021-01-23
有渐变效果的图片资源,它实现的是一个动画效果,我们可以指定多张图片,进行从一张到另一张顺序淡入淡出的显示。
存放位置:res/drawable/
使用方式:
在Java文件中:R.drawable.filename
在xml布局文件中:@[package:]drawable/filename
语法:
<?xml version="1.0" encoding="utf-8"?><transition xmlns: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:id 资源ID。drawable资源的唯一标识。
android:drawable Drawable 资源。 必须的。引用一个Drawable资源。
android:top Integer。 与顶部的距离
android:right Integer。与右边的距离
android:bottom Integer。 与下边的距离
android:left Integer。与左边的距离
另外,我们需要说明的是这个xml最终是被解析为TransitionDrawable对象,所以我们可以通过代码来进行处理。
例如:
<?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>
<ImageButton android:id="@+id/button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/transition" />
ImageButton button = (ImageButton) findViewById(R.id.button);TransitionDrawable drawable = (TransitionDrawable) button.getDrawable();drawable.startTransition(500);
更多相关文章
- Android 滑动效果进阶篇(六)—— 倒影效果
- 三种方式实现自定义圆形页面加载中效果的进度条
- 【eoe资源】如何让Android ListView的平滑滚动
- Android ListView项收缩效果
- android apk编译时可以找到的资源,但在运行时却找不到出错Resourc
- android实战项目二实现画板效果