Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android 分享一個簡單有趣的動畫效果

Android 分享一個簡單有趣的動畫效果

編輯:關於Android編程

本期開始於大家分享幾個簡單又有趣的動畫

效果圖:

\


效果還是不錯的,而實現起來也並沒有多大的難度,上代碼喽

	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 adapter = new ArrayAdapter(
				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);
	}

主要是運用了屬性動畫,關於屬性動畫等我有更多的心得的時候再詳細講述。。本期純屬分享效果,十分的水啊。。。


項目源碼



  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved