【发布时间】:2017-10-12 09:58:22
【问题描述】:
我的RecyclerView 中有一个ViewPager 作为项目。
Viewpager 水平滚动工作正常,但是当我尝试垂直滚动我的RecyclerView 时,选择我的ViewPager 这是RecyclerView 的项目;我的RecyclerView 没有滚动。
mRecyclerViewCarouselInfo.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));
mRecyclerViewCarouselInfo.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
int action = e.getAction();
switch (action) {
case MotionEvent.ACTION_MOVE:
rv.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent event) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
我的 Recyclerview 布局代码如下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="vertical"
android:paddingBottom="@dimen/margin_gap_8">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:listSelector="@drawable/listitem_selector_bg"
android:visibility="visible"/>
</RelativeLayout>
【问题讨论】:
-
对我来说,这段代码本身就是在 RecyclerView 的 ViewHolder 中使用 ViewPager2。
标签: android android-viewpager android-recyclerview