设置RecyclerView的位置(点击回到顶部)

来源:互联网 发布:三星手表gears软件 编辑:程序博客网 时间:2024/06/03 22:59

1  隐藏和显示回到顶部按钮

假设有个RecylerView rvHome;有个adapter 

rvHome.setAdapter(new HomeFragmentAdapter(mContext, result));GridLayoutManager manager = new GridLayoutManager(mContext, 1);//设置滑动到哪个位置了的监听manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {    @Override    public int getSpanSize(int position) {        if(position<=3){            ib_top.setVisibility(View.GONE);        }else {            ib_top.setVisibility(View.VISIBLE);        }        return 1;//只能返回1    }});rvHome.setLayoutManager(manager);//设置只为一列
2 设置点击回到顶部

假设有个图片按钮点击ib_top

ib_top.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {        //回到顶部        rvHome.scrollToPosition(0);    }});



阅读全文
0 0