本期开始于大家分享几个简单又有趣的动画
效果图:
效果还是不错的,而实现起来也并没有多大的难度,上代码喽
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); }
主要是运用了属性动画,关于属性动画等我有更多的心得的时候再详细讲述。。本期纯属分享效果,十分的水啊。。。
原文地址:http://blog.csdn.net/u014163726/article/details/40654847