首页 > 移动平台 > 详细

安卓动画移动放大淡化

时间:2015-03-24 19:43:28      阅读:124      评论:0      收藏:0      [点我收藏+]
public class MainActivity extends Activity {

	Button button1, button2, button3, button4, button5,button6,button7;

	TranslateAnimation up_down;
	TranslateAnimation down_up;
	TranslateAnimation left_right;
	TranslateAnimation right_left;
	AlphaAnimation have_not;
	ScaleAnimation small_big;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		button1 = (Button) findViewById(R.id.button1);
		button2 = (Button) findViewById(R.id.button2);
		button3 = (Button) findViewById(R.id.button3);
		button4 = (Button) findViewById(R.id.button4);
		button5 = (Button) findViewById(R.id.button5);
		button6 = (Button) findViewById(R.id.button6);
		button7 = (Button) findViewById(R.id.button7);

		up_down = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
		up_down.setDuration(500);

		down_up = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
		down_up.setDuration(500);

		left_right = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
		left_right.setDuration(500);

		right_left = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f,
				Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
		right_left.setDuration(500);

		have_not = new AlphaAnimation(1, 0);
		have_not.setFillAfter(true);
		have_not.setDuration(500);

		small_big = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF,
				0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		small_big.setDuration(500);

		button5.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				button1.startAnimation(up_down);
				button2.startAnimation(left_right);
				button3.startAnimation(right_left);
				button4.startAnimation(down_up);
				button6.startAnimation(small_big);
				button7.startAnimation(have_not);

			}
		});

	}
}


安卓动画移动放大淡化

原文:http://luoguoxin.blog.51cto.com/8845916/1623745

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!