1. <animation-listxmlns:android="http://schemas.android.com/apk/res/android"
  2. android:oneshot="false">
  3. <itemandroid:drawable="@drawable/main_frame_01"android:duration="100"/>
  4. <itemandroid:drawable="@drawable/main_frame_02"android:duration="100"/>
  5. <itemandroid:drawable="@drawable/main_frame_03"android:duration="100"/>
  6. <itemandroid:drawable="@drawable/main_frame_04"android:duration="100"/>
  7. <itemandroid:drawable="@drawable/main_frame_05"android:duration="100"/>
  8. <itemandroid:drawable="@drawable/main_frame_06"android:duration="100"/>
  9. <itemandroid:drawable="@drawable/main_frame_07"android:duration="100"/>
  10. <itemandroid:drawable="@drawable/main_frame_08"android:duration="100"/>
  11. <itemandroid:drawable="@drawable/main_frame_09"android:duration="100"/>
  12. <itemandroid:drawable="@drawable/main_frame_10"android:duration="100"/>
  13. <itemandroid:drawable="@drawable/main_frame_11"android:duration="100"/>
  14. <itemandroid:drawable="@drawable/main_frame_12"android:duration="100"/>
  15. <itemandroid:drawable="@drawable/main_frame_13"android:duration="100"/>
  16. <itemandroid:drawable="@drawable/main_frame_14"android:duration="100"/>
  17. <itemandroid:drawable="@drawable/main_frame_15"android:duration="100"/>
  18. <itemandroid:drawable="@drawable/main_frame_16"android:duration="100"/>
  19. <itemandroid:drawable="@drawable/main_frame_17"android:duration="100"/>
  20. <itemandroid:drawable="@drawable/main_frame_18"android:duration="100"/>
  21. <itemandroid:drawable="@drawable/main_frame_19"android:duration="100"/>
  22. </animation-list>
写一个animation-list oneshot是否只跑一次 xmls是命名空间 [java] view plain copy
  1. publicvoidonCreate(BundlesavedInstanceState){
  2. super.onCreate(savedInstanceState);
  3. setContentView(R.layout.aaa);
  4. m_RunButton=(Button)this.findViewById(R.id.Button01);
  5. m_StopButton=(Button)this.findViewById(R.id.Button02);
  6. m_RunButton.setOnClickListener(m_BtnRunClickListener);
  7. m_StopButton.setOnClickListener(m_BtnStopClickListener);
  8. imgView=(ImageView)this.findViewById(R.id.ImageView01);
  9. imgView.setBackgroundResource(R.drawable.animation);
  10. mAnimation=(AnimationDrawable)imgView.getBackground();
  11. //startAnimation(mAnimation);
  12. }

onCreate 中 Animation 需要一个 view 所以 imgView.getBackground()返回一个view background 保证切换图片时不会重叠

animation.start() 不能写在onCreate中否则不能执行,可能系统调用view.invalidate()不能在onCreate调用的原因,否则会冲突```onCreate时

invalidate(废止)。把animation.start() 写在button的响应里。

[java] view plain copy
  1. protectedvoidonResume(){
  2. //TODOAuto-generatedmethodstub
  3. super.onResume();
  4. //mHandler.postDelayed(mRunnable,START_DELAY);
  5. }
  6. privateView.OnClickListenerm_BtnRunClickListener=newView.OnClickListener()
  7. {
  8. publicvoidonClick(Viewarg0){
  9. //TODOAuto-generatedmethodstub
  10. startAnimation(mAnimation);
  11. }
  12. };
  13. privateView.OnClickListenerm_BtnStopClickListener=newView.OnClickListener()
  14. {
  15. publicvoidonClick(Viewarg0){
  16. //TODOAuto-generatedmethodstub
  17. stopAnimation(mAnimation);
  18. }
  19. };
  20. protectedvoidstartAnimation(finalAnimationDrawableanimation){
  21. if(animation!=null&&!animation.isRunning()){
  22. animation.run();
  23. }
  24. }
  25. protectedvoidstopAnimation(finalAnimationDrawableanimation){
  26. if(animation!=null&&animation.isRunning())animation.stop();
  27. }


原文地址: http://blog.csdn.net/wangyi_lin/article/details/6678473

更多相关文章

  1. 设置Android(安卓)app背景图片(Android(安卓)studio)
  2. Android的Actiovity组件
  3. Android(安卓)WebView与 JS 的交互方式
  4. android 使用Intent传递数据之全局变量传递
  5. android 使用Intent传递数据之全局变量传递
  6. android 实现自定义键盘的实例
  7. 处女男学Android(十四)---Android(安卓)重量级数据存储之SQLite
  8. Android的MediaPlayer架构介绍
  9. Android深入四大组件(一)应用程序启动过程

随机推荐

  1. 1.Android(安卓)Studio 环境搭建并配置Ge
  2. 关于使用Google提供的ZXing扫描二维码Dem
  3. Picasso源码分析
  4. StikkyHeader——为滚动视图添加粘性头部
  5. android创建AVD时的报错:Unable to find a
  6. Android(安卓)AndroidManifest.xml 详解
  7. Bitmap.Options和LruCache——Android高
  8. Android(安卓)6.0运行时权限处理
  9. 移动互联网
  10. Android(安卓)ButterKnife Zelezny插件的