Android DemoAndroid开发经验谈Android 开发技术分享

一分钟手握手教你实现RecyclerView的Item动画

2017-06-10  本文已影响830人  小怪兽打葫芦娃

Android程序员面试宝典

安全专题

自定义控件

联网

工具

数据库

源码分析相关面试题

Activity相关面试题

Service相关面试题

与XMPP相关面试题

与性能优化相关面试题

与登录相关面试题

与开发相关面试题

与人事相关面试题

配套视频

http://www.toutiao.com/i6430368196905140737/

直接使用让RecyclerView的Adapter直接继承下面的动画Adapter

public class AnimRecyclerViewAdapter<T extends RecyclerView.ViewHolder>
        extends RecyclerView.Adapter<T> {
    private static final int DELAY = 138;
    private int mLastPosition = -1;
    private Context mContext;
    @Override
    public T onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }
    @Override
    public void onBindViewHolder(T holder, int position) {}
    @Override
    public int getItemCount() {return 0;}
    public void showItemAnim(final View view, final int position) {
        mContext = view.getContext();
        if (position > mLastPosition) {
            view.setAlpha(0);
            view.postDelayed(new Runnable() {
            @Override
            public void run() {
            Animation animation = AnimationUtils.loadAnimation(mContext,
                            R.anim.item_right);
            animation.setAnimationListener(new Animation.AnimationListener() {
             @Override 
             public void onAnimationStart(Animation animation) {
                    view.setAlpha(1);
              }
              @Override 
              public void onAnimationEnd(Animation animation) {}             
               @Override 
               public void onAnimationRepeat(Animation animation) {}
                    });
                    view.startAnimation(animation);
                }
            }, DELAY * position);
            mLastPosition = position;
        }
    }
}


上一篇下一篇

猜你喜欢

热点阅读