我有一个带有ViewPager的MotionLayout。在ViewPager托管的一个片段之一内,我有一个带有两个水平回收的垂直回收模型。但是,滚动的效果很好,但是,当我尝试在内部回收道上水平滚动时,它的工作原理不太好。我似乎尝试垂直滚动(此处的视频:https://youtu.be/94rq5qkr2ew)我怀疑这与我使用的视图的组合有关,但我不确定如何处理修复它或弄清楚什么问题。我已经在内部(水平)回收中尝试了一下,但似乎并没有很大的不同:
recyclerView.setOnTouchListener((v, event) -> {
int action = event.getAction();
View
switch (action) {
case MotionEvent.ACTION_CANCEL:
v.getParent().requestDisallowInterceptTouchEvent(false);
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
case MotionEvent.ACTION_MOVE:
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
});
这是MotionLayout容器的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout android:id="@+id/container"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutDescription="@xml/motion_scene_home_tab">
<com.github.florent37.shapeofview.shapes.DiagonalView
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="0dp"
android:elevation="@dimen/header_elevation_expanded"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shape_diagonal_angle="@dimen/menu_header_angle"
app:shape_diagonal_direction="left"
app:shape_diagonal_position="bottom">
<View
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/redE64"/>
</com.github.florent37.shapeofview.shapes.DiagonalView>
<TextView
android:id="@+id/toolbar_title"
style="@style/title.white"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="@dimen/status_bar_height"
tools:text="Help Center Help Center Help Center "/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:elevation="2dp"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_title"
app:layout_constraintVertical_bias="0.0"
app:tabBackground="@color/transparent"
app:tabIndicatorColor="@color/white"
app:tabSelectedTextColor="@color/white"
app:tabTextColor="@color/white_50_percent"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="0dp"
android:elevation="1dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_pager_guideline"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.35"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/view_pager_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.18"/>
</androidx.constraintlayout.motion.widget.MotionLayout>
它使用以下运动场景:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@layout/fragment_home_end"
app:constraintSetStart="@layout/fragment_home"
app:duration="500">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/view_pager"
app:touchAnchorSide="top"/>
<KeyFrameSet>
<KeyAttribute
android:elevation="0dp"
app:framePosition="0"
app:target="@id/header"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="90"
app:target="@id/header"/>
<KeyAttribute
android:elevation="@dimen/schedule_header_elevation_collapsed"
app:framePosition="100"
app:target="@id/header"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="0"
app:target="@id/toolbar"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="90"
app:target="@id/toolbar"/>
<KeyAttribute
android:elevation="@dimen/schedule_header_elevation_collapsed"
app:framePosition="100"
app:target="@id/toolbar"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="0"
app:target="@id/tabs_bar"/>
<KeyAttribute
android:elevation="0dp"
app:framePosition="90"
app:target="@id/tabs_bar"/>
<KeyAttribute
android:elevation="@dimen/schedule_header_elevation_collapsed"
app:framePosition="100"
app:target="@id/tabs_bar"/>
<KeyAttribute
android:alpha="1"
app:framePosition="0"
app:target="@id/toolbar_title"/>
<KeyAttribute
android:alpha="0"
app:framePosition="100"
app:target="@id/toolbar_title"/>
</KeyFrameSet>
</Transition>
</MotionScene>
知道我如何解决这个问题?还是至少改进它?
给予 nestadScrollingEnabled = false to xml
您可以尝试此组件https://gist.github.com/veeyikpong/AEC06CFAF66DFCAD427A47654953CD7D
样品用法
只需将此组件用作XML中的普通循环系统:
<com.veeyikpong.utils.NestedHorizontalRecyclerView
android:id="@+id/recyclerView"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content />
,你很好!如果有效,请标记为答案:)