关于这个问题,我到处走走了很多,还没有发现任何东西。
我的Viewpager有3个片段,每个片段都有一个RecyclerView作为父对象。
RecyclerView具有多种类型的ViewHolders,其中之一是禁用了手动/用户滚动的自动滚动水平recyclerview。我设法通过拥有自定义的recyclerview并在OnInterceptTouchEvent()回调中返回false来做到这一点。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:cardBackgroundColor="@color/branding_white"
app:cardCornerRadius="4dp"
app:cardElevation="2dp"
tools:ignore="MissingPrefix">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_scroller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clipToPadding="false"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:listitem="@layout/item_scrolling_view" />
<TextView
android:id="@+id/tv_header"
fontPath="@string/font_opensans_semi_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rv_scroller"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:lineSpacingExtra="6sp"
android:text="Test"
android:textColor="#121313"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_sub_heading"
fontPath="@string/font_opensans_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_header"
android:layout_marginStart="10dp"
android:layout_marginTop="4dp"
android:lineSpacingExtra="8sp"
android:text="Test"
android:textColor="#565657"
android:textSize="14sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rv_scroller"
android:layout_alignParentEnd="true"
android:layout_marginTop="28dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="20dp"
android:src="@drawable/ic_play_icon_copy" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
我面临的问题是在整个应用程序中实现流畅的滑动行为。如果我尝试在自动滚动recyclerview的顶部上向左/向右滑动,则Viewpager不会滑动。
到目前为止,我已经尝试过在任何可能的地方重写onInterceptTouchEvent,以及在RecyclerView顶部放置另一个框架布局。
据我所知,当我在RecyclerView上滑动时,Viewpager本身无法通过返回false来拦截事件。
我最终想要实现的目标:
如果我尝试在该RecyclerView上滑动,则该视图无需用户干预即可自动水平滚动并滑动到第二个片段。
我只是找不到正确的方向。我做错了。