首页 > 代码库 > 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<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 分享一个简单有趣的动画效果
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。