您当前的位置: 首页 >  动画
  • 0浏览

    0关注

    674博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

RecyclerView的进场动画、点击动画

沙漠一只雕得儿得儿 发布时间:2018-11-27 15:44:42 ,浏览量:0

下面图片即为本次的运行效果:

 

1.进场动画是在viewholder中的onViewAttachedToWindow()中添加动画即可,动画的代码:
private ScaleInAnimation mSelectAnimation = new ScaleInAnimation();

@Override
    public void onViewAttachedToWindow(DiffVH holder) {
        super.onViewAttachedToWindow(holder);
        addAnimation(holder);
    }

private void addAnimation(DiffVH holder) {
        for (Animator anim : mSelectAnimation.getAnimators(holder.itemView)) {
            anim.setDuration(300).start();
            anim.setInterpolator(new LinearInterpolator());
        }
    }

ScaleInAnimation.java:

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.View;

public class ScaleInAnimation{
    private static final float DEFAULT_SCALE_FROM = .5f;
    private final float mFrom;

    public ScaleInAnimation() {
        this(DEFAULT_SCALE_FROM);
    }

    public ScaleInAnimation(float from) {
        mFrom = from;
    }

    public Animator[] getAnimators(View view) {
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", mFrom, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", mFrom, 1f);
        return new ObjectAnimator[]{scaleX, scaleY};
    }
}
2.每个item的点击效果是一个自定义view,具体看BamLinearLayout.java

使用的话直接在xml中引用即可:



    

    

    

完整的项目地址:

https://github.com/buder-cp/base_component_learn/tree/master/diffut

关注
打赏
1657159701
查看更多评论
立即登录/注册

微信扫码登录

0.0529s