android 逐帧动画

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
	android:oneshot="false"> 		
	<item android:drawable="@drawable/main_frame_01" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_02" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_03" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_04" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_05" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_06" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_07" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_08" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_09" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_10" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_11" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_12" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_13" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_14" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_15" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_16" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_17" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_18" android:duration="100" /> 
	<item android:drawable="@drawable/main_frame_19" android:duration="100" /> 
</animation-list> 
写一个animation-list          oneshot是否只跑一次    xmls是命名空间
 public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.aaa);  

        m_RunButton=(Button)this.findViewById(R.id.Button01);  
        m_StopButton=(Button)this.findViewById(R.id.Button02);  
        m_RunButton.setOnClickListener( m_BtnRunClickListener);  
        m_StopButton.setOnClickListener(m_BtnStopClickListener);  
         
        imgView=(ImageView)this.findViewById(R.id.ImageView01);  
          
        imgView.setBackgroundResource(R.drawable.animation);  
        mAnimation = (AnimationDrawable) imgView.getBackground(); 
        //startAnimation(mAnimation);
    }  

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

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

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

protected void onResume() {  
        // TODO Auto-generated method stub  
        super.onResume();  
        //mHandler.postDelayed(mRunnable, START_DELAY);  
    }  
    private View.OnClickListener m_BtnRunClickListener=new View.OnClickListener()  
    {     
        public void onClick(View arg0) {  
            // TODO Auto-generated method stub  
            startAnimation(mAnimation);  
        }         
    };  
    private View.OnClickListener m_BtnStopClickListener=new View.OnClickListener()  
    {  
        public void onClick(View arg0) {  
            // TODO Auto-generated method stub  
            stopAnimation(mAnimation);  
        }  
          
    };  
    protected void startAnimation(final AnimationDrawable animation) {  
        if (animation != null && !animation.isRunning()) {  
            animation.run();  
        }  
    }  
     
    protected void stopAnimation(final AnimationDrawable animation) {  
        if (animation != null && animation.isRunning()) animation.stop();  
    }  

这样就可以了`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值