【记录】Tom猫——用Animation-list逐帧动画实现
2016-06-03 14:39
405 查看
第一步:准备图片素材,放到res/drawable目录下
图片素材下载地址:http://pan.baidu.com/s/1dFoH82l(若链接失效请联系作者索取)第二步:创建动画文件,放到res/drawable目录下
<?xml version="1.0" encoding="utf-8"?> <!-- 根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画 根标签下,通过item标签对动画中的每一个图片进行声明 android:duration 表示展示所用的该图片的时间长度 --> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@drawable/background" android:duration="100"></item> <item android:drawable="@drawable/poke_belly_right_0001" android:duration="100"/> <item android:drawable="@drawable/poke_belly_right_0002" android:duration="100"/> <item android:drawable="@drawable/poke_belly_right_0003" android:duration="100"/> <item android:drawable="@drawable/poke_belly_right_0004" android:duration="100"/> <item android:drawable="@drawable/poke_belly_right_0005" android:duration="100"/> <item android:drawable="@drawable/poke_belly_right_0006" android:duration="100"/> <item android:drawable="@drawable/poke_belly_right_0007" android:duration="100"/> <item android:drawable="@drawable/poke_belly_right_0008" android:duration="100"/> <item android:drawable="@drawable/background" android:duration="100"></item> </animation-list>
第三步:在布局文件,mian.xml 中引入ImageView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@drawable/ani" /> </RelativeLayout>
第四步:在MianActivity中播放动画
public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imageView = (ImageView) findViewById(R.id.imageView1); final AnimationDrawable background = (AnimationDrawable) imageView.getBackground(); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 停止上一次的动画,然后开始播放 background.stop(); background.start(); } }); }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories