动画Animation之抛物线

package com.example.animation;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;


public class MainActivity extends Activity {
	// 抛物线我们应该定义两个平移的Translate,set让它们并发运动


	private ImageView iv;
	private TranslateAnimation translate01;
	private TranslateAnimation translate02;
	private AnimationSet set;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		iv = (ImageView) findViewById(R.id.main_iv);
		initAnimation();
	}


	private void initAnimation() { // 1,x轴起始位置以什么为基准 2,x起始位置多少f 3,x轴终点位置以什么为基准
									// 4,x终止位置多少f 5,y轴起始位置已什么为基准 6,y轴起始位置多少f
									// 7,y轴终点位置已什么为基准 8,y轴终点位置多少f
		translate01 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_PARENT, 0.8f, Animation.RELATIVE_TO_SELF,
				0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
		translate01.setDuration(3000);
		translate01.setInterpolator(new LinearInterpolator());
		translate01.setFillAfter(true);
//		所要注意的问题是,x轴动了,y轴不动,x轴设置的是线性,
		translate02 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				0.0f, Animation.RELATIVE_TO_PARENT, 0.8f);
		translate02.setDuration(3000);
//					y轴设置的是加速
		translate02.setInterpolator(new AccelerateInterpolator());
		translate02.setFillAfter(true);
		set = new AnimationSet(false);
		set.addAnimation(translate01);
		set.addAnimation(translate02);
		set.setFillAfter(true);
		iv.setAnimation(set);
	}


}


你可能感兴趣的:(动画Animation之抛物线)