Frame Animation帧播放动画

<?xml version="1.0" encoding="utf-8"?>
<animation-list   android:id="@+id/handimation" android:oneshot="false"  
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/a1" android:duration="150" /> 
    <item android:drawable="@drawable/icon" android:duration="150" /> 
    <item android:drawable="@drawable/stat_sad" android:duration="150" /> 
 </animation-list>

 将上面的代码加入res/anim/rocket_thrust.xml

然后在代码中:

ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
      rocketImage.setBackgroundDrawable(getResources().getDrawable(R.drawable.rocket_thrust));
      rocketAnimation = (AnimationDrawable) rocketImage.getBackground();

 

或者

  rocketImage.setBackgroundResource(R.anim.rocket_thrust); 
  rocketAnimation = (AnimationDrawable) rocketImage.getBackground();

 

如果用Tween  Aniamation动画 你的用

rocketImage.setAnimation(AnimationUtils.loadAnimation(this, R.anim.rocket_thrust) );

 

同时还要注意 你的图画不能是黑白的 这样看不出效果,因为屏幕是黑色的 我就因为这个原因 还以为代码错误

然后就是运动

@Override
	  public boolean onTouchEvent(MotionEvent event) {
    	if (event.getAction() == MotionEvent.ACTION_DOWN) {
    		((AnimationDrawable) rocketAnimation).start();
    		return true;
    		}
    		return super.onTouchEvent(event);
    		}

 

在这里没有弄出自动播放 我也没找到原因

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值