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);