项目中常用Animation案例

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>

转载于:https://my.oschina.net/bruces/blog/698449

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值