我有一个 ViewPager
作为我的 RecyclerView
中的一个项目。
Viewpager
水平滚动工作正常但是当我试图通过选择我的 ViewPager
垂直滚动我的 RecyclerView
时,它是 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>
最佳答案
尝试
mRecyclerViewCarouselInfo.setNestedScrollingEnabled(true);
关于android - Viewpager Inside Recyclerview As Item 使用 Viewpager 防止滚动 Recyclerview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46706685/