Android 水平滚动List 一项Item占满一页宽 设定单次滑动一次切换一次Item
背景:水平滚动的List,一项Item占满页面宽度,相当于数量不定的选项卡,每个选项卡占满一页,左右滑动时,如何限制一次只能滑动一个Item
步骤:
1. 水平滚动布局
linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
xxxRecyclerView.setLayoutManager(linearLayoutManager);
xxxAdapter = new SlideAdapter(mList);
xxxRecyclerView.setAdapter(xxxAdapter);
2. 设定单次滑动一次Item(加在setAdapter后面)
PagerSnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(xxxRecyclerView);
作者:人间春风意
扫描左侧的二维码可以赞赏

本作品采用署名-非商业性使用-禁止演绎 4.0 国际 进行许可。

浙公网安备 33010602011771号