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不能直接写在onClickonStartonResume里面,是无效的,无法启动动画,只能写在比如事件监听当中


更多相关文章

  1. Android(安卓)仿微信Activity左右切换 【全局配置Activity显示动
  2. android中类似于gif 实现图片的动画效果
  3. android 启动Activity的四种模式
  4. Android点赞动画效果 ,点赞后加一,2种方法,①补间动画②位移动画
  5. Android:interpolator用法
  6. Java + TestNG + Appium 实现单机多个Android终端并发测试
  7. Android(安卓)中各种XML文件的作用
  8. Android(安卓)清单文件属性大全
  9. android 动态调试笔记

随机推荐

  1. android获取短信所有内容
  2. android 8.0 MountService -->StorageMan
  3. Android 8天入门
  4. android studio :com.android.support:app
  5. FileProvider无法获取外置SD卡问题解决方
  6. Eclipse Indigo - Cannot install Androi
  7. Ubuntu 11.04 下搭建Android NDK开发环境
  8. spring android 编译环境搭建
  9. Android HttpURLConnection网络通信
  10. Android 开发时遇到的两个模拟器问题