一、佈局從底部彈出android
//相對位置 shareLayout.setVisibility(View.VISIBLE);//先設置顯示,再給動畫 Animation alphaAnim = new AlphaAnimation(0.0f, 1.0f); alphaAnim.setDuration(300); alphaAnim.setInterpolator(mContext, android.R.anim.decelerate_interpolator); llShareLayout.startAnimation(alphaAnim); Animation transAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f); transAnimation.setDuration(300); transAnimation.setInterpolator(mContext, android.R.anim.decelerate_interpolator); shareLayout.startAnimation(transAnimation); //絕對位置 public void setVisibility(int visibility, boolean isImmediately) { if (isImmediately) { clearAnimation(); } else { startAnimator(visibility); } super.setVisibility(visibility); } private void startAnimator(int visibility) { clearAnimation(); if (visibility == getVisibility()) { return; } if (visibility == View.VISIBLE) { AnimationSet animationSet = new AnimationSet(true); TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, mEffectBitmapWidth, 0); translateAnimation.setDuration(300); AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1); alphaAnimation.setDuration(300); animationSet.addAnimation(translateAnimation); animationSet.addAnimation(alphaAnimation); startAnimation(animationSet); } else { AnimationSet animationSet1 = new AnimationSet(true); TranslateAnimation translateAnimation1 = new TranslateAnimation(0, 0, 0, mEffectBitmapWidth); translateAnimation1.setDuration(300); AlphaAnimation alphaAnimation1 = new AlphaAnimation(1, 0); alphaAnimation1.setDuration(300); animationSet1.addAnimation(translateAnimation1); animationSet1.addAnimation(alphaAnimation1); startAnimation(animationSet1); }
二、點贊動畫,變大後自動還原佈局
<set xmlns:android="http://schemas.android.com/apk/res/android" > <scale android:duration="300" android:fillAfter="false" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.5" android:toYScale="1.5" android:repeatMode="reverse" android:repeatCount="1"/> </set>
三、點贊按鈕不停縮小閃爍動畫
<set xmlns:android="http://schemas.android.com/apk/res/android" > <scale android:duration="500" android:fillAfter="false" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="0.67" android:toYScale="0.67" android:repeatMode="reverse" android:repeatCount="-1"/> </set>
四、仿nice標籤圓點閃爍code
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" android:fillBefore="false" android:interpolator="@android:anim/accelerate_interpolator" android:startOffset="100"> <scale android:duration="200" android:fillAfter="false" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50.0%" android:pivotY="50.0%" android:toXScale="0.8" android:toYScale="0.8" /> <scale android:duration="200" android:fillAfter="false" android:fromXScale="0.8" android:fromYScale="0.8" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50.0%" android:pivotY="50.0%" android:startOffset="200" android:toXScale="1.25" android:toYScale="1.25" /> <scale android:duration="200" android:fillAfter="false" android:fromXScale="1.25" android:fromYScale="1.25" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50.0%" android:pivotY="50.0%" android:startOffset="400" android:toXScale="1.0" android:toYScale="1.0" /> </set>
五、仿nice標籤圓點水波紋效果xml
//第一個 <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:duration="900" android:fillAfter="false" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50.0%" android:pivotY="50.0%" android:toXScale="29.0" android:toYScale="29.0" /> <alpha android:duration="900" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set> //第二個 <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <scale android:duration="900" android:fillAfter="false" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50.0%" android:pivotY="50.0%" android:startOffset="450" android:toXScale="29.0" android:toYScale="29.0" /> <alpha android:duration="900" android:fromAlpha="1.0" android:startOffset="450" android:toAlpha="0.0" /> </set>