答案 0 :(得分:0)
您可以使用RecyclerViewPager库,在build.gradle
中添加:
编译'com.github.lsjwzh.RecyclerViewPager:lib:v1.2.0@aar'
xml:
<com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
app:rvp_triggerOffset="0.1"
app:rvp_singlePageFling="true"
android:clipToPadding="false"/>
代码:
RecyclerViewPager mRecyclerView = (RecyclerViewPager) view.findViewById(R.id.list);
// setLayoutManager like normal RecyclerView, you do not need to change any thing.
LinearLayoutManager layout = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
mRecyclerView.setLayoutManager(layout);
//set adapter
//You just need to implement ViewPageAdapter by yourself like a normal RecyclerView.Adpater.
mRecyclerView.setAdapter(new RecyclerView.Adpater<X>());
// That is all.
更新
将此maven { url "https://jitpack.io" }
添加到allprojects->repositories
块的build.gradle(项目级别)下,您的代码应如下所示:
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}