支持水平 、竖直nestedscroll刷新控件重构

RefreshLayout

nestscroll Refreshing重构
支持水平 竖直双方向
Github地址

GIF.gif

GIF2.gif

GIF3.gif

xml

 

code

final RefreshLayout layout=findViewById(R.id.Refresh);
        layout.setListener(new RefreshLayout.Callback1() {
            @Override
            public void call(RefreshLayout.State state) {
                super.call(state);
                if(state== RefreshLayout.State.REFRESHING||state== RefreshLayout.State.LOADING){
                    layout.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            layout.NotifyCompleteRefresh1(layout.findInHeaderView(R.id.textView).getMeasuredWidth()+10,"为你更新了很多信息");
                        }
                    },3000);
                }
            }
            @Override
            public void call(RefreshLayout.State state, int scroll) {
                super.call(state, scroll);
            }
        });
        RecyclerView recyclerView=layout.getmScroll();
        recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false));
        recyclerView.setAdapter(new RecyclerView.Adapter() {
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                return new RecyclerView.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item,parent,false)) {
                    @Override
                    public String toString() {
                        return super.toString();
                    }
                };
            }

            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

            }

            @Override
            public int getItemCount() {
                return 30;
            }
        });
        layout.setOrentation(RefreshLayout.Orentation.HORIZONTAL);

more properities

    
        
        
        
        
        
        

        
            
            
        
        
        
        
        
        
        
        
        
    

GOLBAL SET

 RefreshLayout.init(new RefreshLayout.DefaultBuilder()
 .xxx
.xxx
 .setBaseRefreshWrap(MyRefreshWrap.class))
 .xxx
.xxx);

SELF RefreshWrap AS SAMPLE

public class MyRefreshWrap extends RefreshLayout.BaseRefreshWrap {
    private ImageView mHeaderimageView;
    private TextView mHeadertextView;
    private ProgressBar mHeaderPrgress;
    private ImageView mFooterimageView;
    private TextView mfootertextView;
    private ProgressBar mfootPrgress;
    private WeakReference layoutWeakReference;

    public RefreshLayout getRefreshLayout() {
        return layoutWeakReference.get();
    }

    private RefreshLayout.State currentState;
    String[] title;

    public void onPullHeader(View view, int scrolls) {
        /**
         * 完成状态时不要改变字
         */
        if(currentState== RefreshLayout.State.REFRESHCOMPLETE||currentState== RefreshLayout.State.REFRESHING){
            return;
        }
        if (mHeadertextView!=null&&scrolls > getRefreshLayout().getmHeaderRefreshPosition()) {
            mHeadertextView.setText(title[1]);
        } else {
            mHeadertextView.setText(title[0]);
        }

    }

    public void onPullFooter(View view, int scrolls) {
        /**
         * 完成状态时不要改变字
         */
        if(currentState== RefreshLayout.State.LOADINGCOMPLETE||currentState==RefreshLayout.State.LOADING){
            return;
        }
        if (mfootertextView!=null&&scrolls > getRefreshLayout().getmFooterRefreshPosition()) {
            mfootertextView.setText(title[4]);
        } else {
            mfootertextView.setText(title[3]);
        }
    }

    public void OnStateChange(RefreshLayout.State state) {
        currentState=state;
        switch (state) {
            case REFRESHCOMPLETE:
                mHeaderPrgress.setVisibility(View.INVISIBLE);
                mHeadertextView.setText(data);
                break;
            case LOADING:
                mfootPrgress.setVisibility(View.VISIBLE);
                mfootertextView.setText(title[5]);
                break;
            case REFRESHING:
                mHeaderPrgress.setVisibility(View.VISIBLE);
                mHeadertextView.setText(title[2]);
                break;
            case LOADINGCOMPLETE:
                mfootPrgress.setVisibility(View.INVISIBLE);
                mfootertextView.setText(data);
                break;
            case IDEL:
                break;
            case PULL_HEADER:
                break;
            case PULL_FOOTER:
                break;
        }

    }
    @Override
    protected void initView(RefreshLayout layout) {
        super.initView(layout);
        layoutWeakReference=new WeakReference(layout);
        View header = layout.getmHeader();
        View footer = layout.getmFooter();
        if(header!=null) {
            mHeaderimageView = header.findViewById(R.id.imageView);
            mHeadertextView = header.findViewById(R.id.textView);
            mHeaderPrgress = header.findViewById(R.id.progressBar);
        }
        if(footer!=null) {
            mFooterimageView = footer.findViewById(R.id.imageView);
            mfootertextView = footer.findViewById(R.id.textView);
            mfootPrgress = footer.findViewById(R.id.progressBar);
        }
        String[] tempVertical={"下拉刷新", "释放刷新", "正在刷新中", "上拉加载", "释放加载", "正在加载中"};
        String[] tempHorizontal={"右拉刷新", "释放刷新", "正在刷新中", "左拉加载", "释放加载", "正在加载中"};
        title=(layout.getOrentation()== RefreshLayout.Orentation.VERTICAL)?
                tempVertical:tempHorizontal;
    }
}

你可能感兴趣的:(支持水平 、竖直nestedscroll刷新控件重构)