简体   繁体   English

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

[英]Is it possible to merge touch events outside and inside the RecyclerView?

I'm building a children's app and want to make it user friendly for them by allowing them to touch outside the RecyclerView first and at the same time be able to scroll and touch within the RecyclerView. 我正在构建一个儿童应用程序,并希望通过允许他们先在RecyclerView外部触摸,同时能够在RecyclerView内滚动和触摸,使其对用户友好。

I've tried changing the width and height of the RecyclerView from wrap_content to match_parent/match_constraint, without any luck. 我试过将RecyclerView的宽度和高度从wrap_content更改为match_parent / match_constraint,没有任何运气。

Layout for the main activity: 主要活动的布局:

<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>

So basically if the first touch event is triggered outside the RecyclerView, then it is not possible to scroll or touch within the RecyclerView. 因此,基本上,如果第一次触摸事件是在RecyclerView外部触发的,则不可能在RecyclerView内滚动或触摸。 What I'm looking for is the possibility to scroll and touch within the RecyclerView with multiple fingers on the screen at the same time, no matter where the first touch event started. 我正在寻找的是可以在RecyclerView中用多个手指同时在屏幕上滚动和触摸的可能性,无论第一次触摸事件从何处开始。

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM