码迷,mamicode.com
首页 > 移动开发 > 详细

Android 分享一个简单有趣的动画效果

时间:2014-10-31 15:40:08      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:android   属性动画   动画效果   

本期开始于大家分享几个简单又有趣的动画

效果图:

bubuko.com,布布扣


效果还是不错的,而实现起来也并没有多大的难度,上代码喽

	public int id[] = { R.drawable.fengjing_1, R.drawable.fengjing_2,
			R.drawable.fengjing_3, R.drawable.fengjing_4,
			R.drawable.fengjing_5, R.drawable.fengjing_6 };

	public String list[] = { "一", "二", "三", "四", "五", "六" };
	private ListView mListView;
	private ImageView mImageView;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
	}

	private void initView() {
		mListView = (ListView) findViewById(R.id.list);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
				MainActivity.this, android.R.layout.simple_list_item_1, list);
		mListView.setAdapter(adapter);
		mListView.setOnItemClickListener(this);
		mImageView = (ImageView) findViewById(R.id.img);
		mImageView.setOnClickListener(this);
	}

	@SuppressLint("NewApi")
	private void animation(final int position) {
		final View vis;
		final View inVis;
		if (mListView.getVisibility() == View.VISIBLE) {
			vis = mListView;
			inVis = mImageView;
		} else {
			vis = mImageView;
			inVis = mListView;
		}
		ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(vis,
				"RotationY", 0f, 90f);
		objectAnimator.setDuration(500);
		objectAnimator.start();
		final ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(
				inVis, "RotationY", -90f, 0f);
		objectAnimator2.setDuration(500);
		objectAnimator.addListener(new AnimatorListenerAdapter() {
			@Override
			public void onAnimationEnd(Animator animation) {
				super.onAnimationEnd(animation);
				objectAnimator2.start();
				vis.setVisibility(View.GONE);
				mImageView.setImageResource(id[position]);
				inVis.setVisibility(View.VISIBLE);
			}
		});

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		animation(arg2);
	}

	@Override
	public void onClick(View arg0) {
		animation(0);
	}

主要是运用了属性动画,关于属性动画等我有更多的心得的时候再详细讲述。。本期纯属分享效果,十分的水啊。。。


项目源码



Android 分享一个简单有趣的动画效果

标签:android   属性动画   动画效果   

原文地址:http://blog.csdn.net/u014163726/article/details/40654847

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!