android 仿蘑菇街喜欢
2015-10-29 14:18
711 查看
采用三个view设置动画 感觉有点麻烦 ..不知谁有更好的解决
布局文件 :
<pre name="code" class="html"><FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:id="@+id/layout_mgj_like" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv_mgj_like_i" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:visibility="gone" android:layout_height="wrap_content"/> <ImageView android:id="@+id/iv_mgj_like_ii" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" android:layout_centerHorizontal="true" android:layout_centerVertical="true"/> <ImageView android:id="@+id/iv_mgj_like_iii" android:background="@drawable/mgj_unlike" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout> <RelativeLayout android:id="@+id/layout_mgj_unlike" android:visibility="gone" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv_mgj_unlike_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/iv_mgj_unlike_right" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/iv_mgj_unlike_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@+id/iv_mgj_unlike_left"/> </RelativeLayout> </FrameLayout>
[/code]
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Source Code Pro';font-size:12.0pt;">
application代码:
<pre name="code" class="java">//仿蘑菇街 喜欢 final RelativeLayout layoutMgjLike = (RelativeLayout) findViewById(R.id.layout_mgj_like); final ImageView ivMgjlikei = (ImageView) findViewById(R.id.iv_mgj_like_i); final ImageView ivMgjlikeii = (ImageView) findViewById(R.id.iv_mgj_like_ii); final ImageView ivMgjlikeiii = (ImageView) findViewById(R.id.iv_mgj_like_iii); final RelativeLayout layoutMgjUnlike = (RelativeLayout) findViewById(R.id.layout_mgj_unlike); final ImageView ivMgjUnlikeLeft = (ImageView) findViewById(R.id.iv_mgj_unlike_left); final ImageView ivMgjUnlikeRight = (ImageView) findViewById(R.id.iv_mgj_unlike_right); layoutMgjLike.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ivMgjlikei.setBackgroundResource(R.drawable.mgj_like); ivMgjlikeii.setBackgroundResource(R.drawable.mgj_like); ivMgjlikeiii.setBackgroundResource(R.drawable.mgj_like); ivMgjlikeii.setVisibility(View.VISIBLE); ivMgjlikei.setVisibility(View.VISIBLE); AnimatorSet setLike = new AnimatorSet(); ObjectAnimator animIScaleX = ObjectAnimator.ofFloat(ivMgjlikei, "scaleX", 0.0f, 4.0f); ObjectAnimator animIScaleY = ObjectAnimator.ofFloat(ivMgjlikei, "scaleY", 0.0f, 4.0f); ObjectAnimator animIAlpha = ObjectAnimator.ofFloat(ivMgjlikei, "alpha", 1.0f, 0.0f); ObjectAnimator animIIScaleX = ObjectAnimator.ofFloat(ivMgjlikeii, "scaleX", 0.0f, 2.5f); ObjectAnimator animIIScaleY = ObjectAnimator.ofFloat(ivMgjlikeii, "scaleY", 0.0f, 2.5f); ObjectAnimator animIIAlpha = ObjectAnimator.ofFloat(ivMgjlikeii, "alpha", 1.0f, 0.5f); ObjectAnimator animIIIScaleX = ObjectAnimator.ofFloat(ivMgjlikeiii, "scaleX", 0.0f, 1.5f); ObjectAnimator animIIIScaleY = ObjectAnimator.ofFloat(ivMgjlikeiii, "scaleY", 0.0f, 1.5f); ObjectAnimator animIIIAlpha = ObjectAnimator.ofFloat(ivMgjlikeiii, "alpha", 1.0f, 0.8f); setLike.play(animIScaleX).with(animIScaleY).with(animIAlpha) .with(animIIScaleX).with(animIIScaleY).with(animIIAlpha) .with(animIIIScaleX).with(animIIIScaleY).with(animIIIAlpha); setLike.setDuration(500).start(); setLike.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); AnimatorSet setlikeEnd = new AnimatorSet(); ObjectAnimator animIIISmallScaleX = ObjectAnimator.ofFloat(ivMgjlikeiii, "scaleX", 1.5f, 1.0f); ObjectAnimator animIIISmallScaleY = ObjectAnimator.ofFloat(ivMgjlikeiii, "scaleY", 1.5f, 1.0f); ObjectAnimator animIIITohighAlpha = ObjectAnimator.ofFloat(ivMgjlikeiii, "alpha", 0.8f, 1.0f); setlikeEnd.play(animIIITohighAlpha).with(animIIISmallScaleX).with(animIIISmallScaleY); setlikeEnd.setDuration(200).start(); ivMgjlikeii.setVisibility(View.GONE); ivMgjlikei.setVisibility(View.GONE); layoutMgjUnlike.setVisibility(View.VISIBLE); } }); } }); layoutMgjUnlike.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { layoutMgjLike.setVisibility(View.GONE); ivMgjUnlikeLeft.setBackgroundResource(R.drawable.mgj_unlike_left); ivMgjUnlikeRight.setBackgroundResource(R.drawable.mgj_unlike_right); AnimatorSet setUnlike = new AnimatorSet(); ObjectAnimator animTranslationY = ObjectAnimator.ofFloat(ivMgjUnlikeLeft, "translationY", 0.0f, 60f); ObjectAnimator animTranslationX = ObjectAnimator.ofFloat(ivMgjUnlikeLeft, "translationX", 0.0f, -60f); ObjectAnimator animRotate = ObjectAnimator.ofFloat(ivMgjUnlikeLeft, "rotation", 0, -60); ObjectAnimator animAlpha = ObjectAnimator.ofFloat(ivMgjUnlikeLeft, "alpha", 1.0f, 0.0f); ObjectAnimator animRightTranslationY = ObjectAnimator.ofFloat(ivMgjUnlikeRight, "translationY", 0.0f, 60f); ObjectAnimator animRightTranslationX = ObjectAnimator.ofFloat(ivMgjUnlikeRight, "translationX", 0.0f, 60f); ObjectAnimator animRightRotate = ObjectAnimator.ofFloat(ivMgjUnlikeRight, "rotation", 0, 60); ObjectAnimator animRightAlpha = ObjectAnimator.ofFloat(ivMgjUnlikeRight, "alpha", 1.0f, 0.0f); setUnlike.play(animTranslationY).with(animRotate).with(animTranslationX).with(animAlpha) .with(animRightTranslationY).with(animRightRotate).with(animRightTranslationX).with(animRightAlpha); setUnlike.setDuration(400).start(); setUnlike.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); layoutMgjLike.setVisibility(View.VISIBLE); ivMgjlikeiii.setBackgroundResource(R.drawable.mgj_unlike); layoutMgjUnlike.setVisibility(View.GONE); } }); } });
源码:http://download.csdn.net/detail/u010906557/9223541
相关文章推荐
- Android按比例布局之layout_weight和weightSum的使用
- 【Android Studio学习】
- Android Studio 简介及导入 jar 包和第三方开源库方法
- android中像素单位dp、px、pt、sp的比较
- android中像素单位dp、px、pt、sp的比较
- android五种布局模式
- android五种布局模式
- Android SDK Timer的schedule()方法的正确使用
- Android服务开发经验——优雅地活着(唤醒)
- Android视频开发国人开发的Vitamio开源项目
- Android 5.0源码分析---startService与bindService的区别
- android悬浮窗口的实现
- Android4.0以上版本比较靠谱的获取手机屏幕分辨率的方法
- android 悬浮窗使用surfaceview的问题
- 在Android Studio添加SO library
- Android保存图片(可能屏幕截图的)到系统图库
- android 瀑布流照片墙
- android中的文件操作详解以及内部存储和外部存储
- Android开发抢手,如何培养成移动开发高手?
- Android还在用Toast?你Out啦,该试试Snackbar了