解决使用AnimationDrawable无法播放动画的问题
2012-07-04 11:02
633 查看
第一种方式启动帧动画:(在Activity启动时会自动运行动画)
第二种方式启动动画:(在Activity启动时会自动运行动画)
第三种方式启动动画:(在Activity启动时会自动运行动画)
这个已经测试,肯定管用
第四种方式启动动画:(在Activity启动时会自动运行动画)
这个ad.start不能直接写在onClick,onStart,onResume里面,是无效的,无法启动动画,只能写在比如事件监听当中
其他文章:
http://www.open-open.com/lib/view/open1329385807906.html http://blog.csdn.net/fuuckwtu/article/details/6518571
AnimationDrawable ad; ImageView iv = (ImageView) findViewById(R.id.animation_view); iv.setBackgroundResource(R.drawable.animation); ad = (AnimationDrawable) iv.getBackground(); iv.getViewTreeObserver().addOnPreDrawListener(opdl); //当一个视图树将要绘制时产生事件,可以添加一个其事件处理函数 OnPreDrawListener opdl=new OnPreDrawListener(){ @Override public boolean onPreDraw() { ad.start(); return true; //注意此行返回的值 } };
第二种方式启动动画:(在Activity启动时会自动运行动画)
ImageView image = (ImageView) findViewById(R.id.animation_view); image.setBackgroundResource(R.anim.oldsheep_wait); animationDrawable = (AnimationDrawable) image.getBackground(); RunAnim runAnim=new RunAnim(); runAnim.execute(""); class RunAnim extends AsyncTask<String, String, String> { @Override protected String 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(new Runnable() { @Override public void run() { animationDrawable.start(); } });
第四种方式启动动画:(在Activity启动时会自动运行动画)
ImageView image = (ImageView) findViewById(R.id.animation_view); image.setBackgroundResource(R.anim.oldsheep_wait); animationDrawable = (AnimationDrawable) image.getBackground(); @Override public void onWindowFocusChanged(boolean hasFocus) { animationDrawable.start(); super.onWindowFocusChanged(hasFocus); }
这个ad.start不能直接写在onClick,onStart,onResume里面,是无效的,无法启动动画,只能写在比如事件监听当中
其他文章:
http://www.open-open.com/lib/view/open1329385807906.html http://blog.csdn.net/fuuckwtu/article/details/6518571
相关文章推荐
- 解决使用AnimationDrawable无法播放动画的问题(转)
- 解决使用AnimationDrawable无法播放动画的问题
- 解决使用AnimationDrawable无法播放动画的问题
- 解决AnimationDrawable动画不运行的问题
- 解决node-webkit下使用<audio>标签无法播放音频的问题
- 解决在onCreate()中AnimationDrawable只播放第一张图片的问题
- 使用双缓冲技术解决动画播放闪烁问题
- Android使用VideoView出现无法播放此视频问题的解决方法
- Android 使用Webview无法播放视频问题的解决办法
- Unity3D animation import issue | 模型导入,动画无法播放问题
- iOS每日一记之———————————————Gif使用新的SDwebimage无法播放的问题解决
- 解决Activity onCreate()时AnimationDrawable动画不运行的问题
- [转载]使用EasyRTMP推送RTMP流flash播放器无法正常播放的问题解决
- AnimationDrawable在2.2系统上开始动画后无法显示的问题
- Android使用SurfaceView代替AnimationDrawable播放多图帧动画,避免OOM和卡顿
- 解决AJAX中使用UpdatePanel后再用Response.Write();等无法弹出对话框问题
- mac下使用android studio,解决无法打开问题。
- 在使用webView播放flash或视频文件时无法关闭声音的问题
- 解决nw.js中无法播放mp3音频问题
- 解决Ubuntu14.04 64bit 安装AndroidSDK后adb命令无法使用问题