项目中常用Animation案例

原创
2016/06/21 14:24
阅读数 217

1、布局从底部弹出

//相对位置
 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);
        }

2、点赞动画,变大后自动还原

<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>

3、点赞按钮不停缩小闪烁

<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>

4、仿nice标签圆点闪烁

<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>

5、仿nice标签圆点水波纹效果

//第一个
<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>
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部