`
rocky_lei
  • 浏览: 41146 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

android 逐帧动画

 
阅读更多

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

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

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

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

 

[java] view plaincopy
  1. protected void onResume() {    
  2.         // TODO Auto-generated method stub    
  3.         super.onResume();    
  4.         //mHandler.postDelayed(mRunnable, START_DELAY);    
  5.     }    
  6.     private View.OnClickListener m_BtnRunClickListener=new View.OnClickListener()    
  7.     {       
  8.         public void onClick(View arg0) {    
  9.             // TODO Auto-generated method stub    
  10.             startAnimation(mAnimation);    
  11.         }           
  12.     };    
  13.     private View.OnClickListener m_BtnStopClickListener=new View.OnClickListener()    
  14.     {    
  15.         public void onClick(View arg0) {    
  16.             // TODO Auto-generated method stub    
  17.             stopAnimation(mAnimation);    
  18.         }    
  19.             
  20.     };    
  21.     protected void startAnimation(final AnimationDrawable animation) {    
  22.         if (animation != null && !animation.isRunning()) {    
  23.             animation.run();    
  24.         }    
  25.     }    
  26.        
  27.     protected void stopAnimation(final AnimationDrawable animation) {    
  28.         if (animation != null && animation.isRunning()) animation.stop();    
  29.     }    


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics