美文网首页
简单实现RecyclerView版本的竖向翻页效果

简单实现RecyclerView版本的竖向翻页效果

作者: enjoycc97 | 来源:发表于2019-08-13 20:24 被阅读0次

    1实现子页面撑满父布局,这样页面就只能显示一个个页面了
    recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    子布局
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    类似于这种长宽都和父亲一样大

    2 设置每次滑动滑动页面底部
    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(recyclerView);

    3监听页面加载到下一个页面
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    LinearLayoutManager manager = (LinearLayoutManager) recyclerView1.getLayoutManager();
    int first = manager.findFirstVisibleItemPosition();
    if (first != last) {
    last = first;
    Toast.makeText(MainActivity.this, "" + first, Toast.LENGTH_SHORT).show();
    }

            }
        });
    

    参考项目:

    相关文章

      网友评论

          本文标题:简单实现RecyclerView版本的竖向翻页效果

          本文链接:https://www.haomeiwen.com/subject/kyzbjctx.html