Tween 补间动画(软编码方式)

/**
 * Tween 动画
 * 
 * @author lilin
 * @date 2011-9-5 下午04:03:40
 * @ClassName: Main
 * @Description: 通过XML布局的方式
 */
public class MainActivity extends Activity implements OnClickListener {
	private Button b1, b2, b3, b4;
	private ImageView imageView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		imageView = (ImageView) findViewById(R.id.ImageView01);
		b1 = (Button) findViewById(R.id.Button01);
		b2 = (Button) findViewById(R.id.Button02);
		b3 = (Button) findViewById(R.id.Button03);
		b4 = (Button) findViewById(R.id.Button04);
		b1.setOnClickListener(this);
		b2.setOnClickListener(this);
		b3.setOnClickListener(this);
		b4.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.Button01:// 创建Sacle(尺寸)变化动画
			Animation scaleAnimation = AnimationUtils.loadAnimation(
					MainActivity.this, R.anim.my_scale);
			imageView.startAnimation(scaleAnimation);// 开始动画
			break;
		case R.id.Button02:// 创建Alpha(渐变)动画
			Animation alphaAnimation = AnimationUtils.loadAnimation(
					MainActivity.this, R.anim.my_alpha);
			imageView.startAnimation(alphaAnimation);
			break;
		case R.id.Button03:// 创建translate(位置变化)动画
			Animation translateAnimation = AnimationUtils.loadAnimation(
					MainActivity.this, R.anim.my_translate);
			imageView.startAnimation(translateAnimation);
			break;
		case R.id.Button04:// 创建rotate(旋转)动画
			Animation rotateAnimation = AnimationUtils.loadAnimation(
					MainActivity.this, R.anim.my_rotate);
			rotateAnimation.setDuration(3000);
			imageView.startAnimation(rotateAnimation);
			break;
		default:
			break;
		}

	}
}

 my_alpha.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
	<alpha 
	android:fromAlpha="0.1" 
	android:toAlpha="1.0"
	android:duration="5000" />
</set>

 

my_rotate.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">  
   <rotate 
   		android:fromDegrees="0"
   		android:toDegrees="-180"
   		android:pivotX="50%"
   		android:pivotY="50%"
   		android:duration="5000"
   />
</set>

 

my_scale.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">  
   <scale 
   		android:fromXScale="0.0"
   		android:toXScale="1.0"
   		android:fromYScale="0.0"
   		android:toYScale="1.0"
   		android:pivotX="50%"
   		android:pivotY="50%"
   		android:duration="5000"
   />
</set>

 

my_translate.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">  
   <translate
   		android:fromXDelta="10"
   		android:toXDelta="100"
   		android:fromYDelta="10"
   		android:toYDelta="100"
   />
</set>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值