android 动画简单介绍

很简单的动画,可以从APIDEMO里找到。

android 动画简单介绍_第1张图片

@Override 
public void onItemSelected(AdapterView<?> parent, View v, int position, long id)
{  
	final View target=(View)findViewById(R.id.target);  
	final View targetParent=(View)target.getParent();//得到动画  
	Animation animation= new TranslateAnimation(0.0f,
	targetParent.getWidth() - target.getWidth() - targetParent.getPaddingLeft() - targetParent.getPaddingRight(), 0.0f, 0.0f);  
	animation.setDuration(1000);  
	animation.setStartOffset(300);  
	animation.setRepeatMode(Animation.RESTART);  
	animation.setRepeatCount(Animation.INFINITE);  
	//选择动来类型  
	switch (position)
	{  
	case 0:  
		animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_interpolator));
		break;  
	case 1:  
		animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.decelerate_interpolator));
		break;  
	case 2:  
		animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.accelerate_decelerate_interpolator));
		break;  
	case 3:  
		animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.anticipate_interpolator));
		break;  
	case 4:  
		animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.overshoot_interpolator));
		break;  
	case 5:  
		animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.anticipate_overshoot_interpolator));
		break;  
	case 6:  
		animation.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.bounce_interpolator));
		break;
	}  
	target.startAnimation(animation);
}

代码


你可能感兴趣的:(android 动画简单介绍)