是否可以在RecyclerView内外合并触摸事件?

时间:2019-05-29 08:44:43

标签: android xml android-layout

我正在构建儿童应用程序,并希望通过允许他们首先在RecyclerView外部触摸,同时能够在RecyclerView内滚动和触摸来使其对用户友好。

我尝试将RecyclerView的宽度和高度从wrap_content更改为match_parent / match_constraint,没有任何运气。

主要活动的布局:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:background="@color/colorBackground">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view_grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        android:clipChildren="false"
        android:clipToPadding="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/main_toolbar"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

因此,基本上,如果第一次触摸事件是在RecyclerView外部触发的,则无法在RecyclerView内滚动或触摸。我要寻找的是可以在RecyclerView中用多个手指同时在屏幕上滚动和触摸,而不管第一次触摸事件从何处开始。

1 个答案:

答案 0 :(得分:-1)

You can put yor RecyclerView within a nested scrollView like this.

  <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="40dp"
        android:background="#88222222">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:padding="5dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#dfdfdfdf">
        </android.support.v7.widget.RecyclerView>

    </android.support.v4.widget.NestedScrollView>

hope you get the answer.

相关问题