在我的活动中,我有由片段组成的ViewPager。我已经使用自定义视图Pager禁用了ViewPager上的滑动运动。
我的片段布局有垂直recycle view,在这个recycle view中有多个水平recycle view。
为了确保我的 AppBarLayout 正确响应滚动行为,我以编程方式在每个水平回收器视图上将 nestedScrollingEnabled 设置为 false。
附言我使用的是recylerview版本25.4.0
问题在于,正如您在上面附加的gif中看到的那样,要滚动水平回收器视图,触摸应该完全横向,即使在水平回收器视图上略微倾斜的运动,垂直回收器视图也会拾取该事件并垂直向上滚动页面
自定义视图页面.java
public class CustomViewPager extends ViewPager {
private boolean enabled;
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}
}
片段布局
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_productoverview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/windowBackground"/>
回收站内部项目的布局_产品概述(垂直回收站视图)
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="@+id/layout_section_header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#ebedff"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<experttag.nurserylive.util.ui.widget.WhitneySemiBoldTextView
android:id="@+id/textview_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TOP FEATURED"
android:textColor="#3f4266"
android:textSize="16sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
app:layout_constraintVertical_bias="0.19"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"/>
<experttag.nurserylive.util.ui.widget.WhitneySemiBoldTextView
android:id="@+id/textview_item_viewall"
style="@style/AppTheme.TextLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#3f4266"
android:text="@string/btn_view_all_caps"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBaseline_toBaselineOf="@+id/textview_item_name"/>
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_item_section"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_section_header"/>
</android.support.constraint.ConstraintLayout>
水平回收查看:@id/recyclerview_item_section
使用BetterRecyclerView解决了这个问题
查看演示
阅读解释
更好的回收者视图.java