Android简单逐帧动画Frame的实现
Android简单逐帧动画Frame的实现
1、逐帧动画
即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影。
2、实现步骤:
1、
在工程里面导入要播放的图片。此简单例子中为start_icon1,2,3.
2、
在工程res文件目录下新建一个anim文件夹,在里面新建一个start_animation.xml格式文件,此文件用来定义动画播放图片的顺序及每一张图片显示停留时间。
例如下:
<?xml version="1.0" encoding="utf-8"?>
android:oneshot="false">
注:此蓝色部分依次显示的图片,存放在drawable-mdpi文件下,一般1秒钟播放24张图片(帧)就感觉播放流畅了,即duration为40左右,默认单位为毫秒。
3、布局文件:
布局文件中添加一ImageView控件,用来播放动画图片。具体布局如下:
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >
4、代码部分:
public class TestActivity extends Activity
{
AnimationDrawable anim;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.start_screen);
ImageView image = (ImageView) findViewById(R.id.image);
// image.setBackgroundResource(R.anim.start_animation);
anim = (AnimationDrawable) image.getBackground();
Button start = (Button) findViewById(R.id.button1);
Button stop = (Button) findViewById(R.id.button2);
start.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.start();
}
});
stop.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.stop();
}
});
}
}
注:第三四步中的紫色部分,只要选择一个就可以,两个都写显得累赘,主要功能是指定播放的资源图片。
小结:这种应用在实际应用中应该不会用到,对于初学着来说,拿着玩下还是蛮有意思的,不仅增强了对Android学习的兴趣,同时也能加深对制造电影的一些了解,
更多相关文章
- 一款常用的 Squid 日志分析工具
- GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
- RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
- Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
- 四、Android.mk之编译生成可执行文件
- android AVD 启动时报错(emulator: erroremulator:ERROR:This AVD'
- Android中的Gallery的使用
- Unity3D调用Android接口
- Google Maps Android(安卓)API v2 (3)- 地图添加到Android应用程