Android中帧动画在Activity启动时自动运行的几种方式
Android中帧动画在Activity启动时自动运行的几种方式
http://www.eoeandroid.com/blog-468046-657.html
帧动画:
第一种方式启动帧动画:(在Activity启动时会自动运行动画)
AnimationDrawablead;
ImageView iv = (ImageView) findViewById(R.id.animation_view);
iv.setBackgroundResource(R.drawable.animation);
ad= (AnimationDrawable) iv.getBackground();
iv.getViewTreeObserver().addOnPreDrawListener(opdl);
//当一个视图树将要绘制时产生事件,可以添加一个其事件处理函数
OnPreDrawListeneropdl=newOnPreDrawListener(){
@Override
publicbooleanonPreDraw() {
ad.start();
returntrue; //注意此行返回的值
}
};
第二种方式启动动画:(在Activity启动时会自动运行动画)
ImageView image = (ImageView) findViewById(R.id.animation_view);
image.setBackgroundResource(R.anim.oldsheep_wait);
animationDrawable= (AnimationDrawable) image.getBackground();
RunAnim runAnim=newRunAnim();
runAnim.execute("");
classRunAnimextendsAsyncTask<String, String, String>
{
@Override
protectedString doInBackground(String... params)
{
if(!animationDrawable.isRunning())
{
animationDrawable.stop();
animationDrawable.start();
}
return"";
}
}
第三种方式启动动画:(在Activity启动时会自动运行动画)
ImageView image = (ImageView) findViewById(R.id.animation_view);
image.setBackgroundResource(R.anim.oldsheep_wait);
animationDrawable= (AnimationDrawable) image.getBackground();
image.post(newRunnable()
{
@Override
publicvoidrun()
{
animationDrawable.start();
}
});
第四种方式启动动画:(在Activity启动时会自动运行动画)
ImageView image = (ImageView) findViewById(R.id.animation_view);
image.setBackgroundResource(R.anim.oldsheep_wait);
animationDrawable= (AnimationDrawable) image.getBackground();
@Override
publicvoidonWindowFocusChanged(booleanhasFocus)
{
animationDrawable.start();
super.onWindowFocusChanged(hasFocus);
}
这个ad.start不能直接写在onClick,onStart,onResume里面,是无效的,无法启动动画,只能写在比如事件监听当中
更多相关文章
- Android(安卓)仿微信Activity左右切换 【全局配置Activity显示动
- android中类似于gif 实现图片的动画效果
- android 启动Activity的四种模式
- Android点赞动画效果 ,点赞后加一,2种方法,①补间动画②位移动画
- Android:interpolator用法
- Java + TestNG + Appium 实现单机多个Android终端并发测试
- Android(安卓)中各种XML文件的作用
- Android(安卓)清单文件属性大全
- android 动态调试笔记