简体   繁体   中英

RecyclerView on Bottom sheet can not scroll?

I want to recyclerView on Bottom sheet can scroll but i cant. I try use OntouchListenner in RecyclerView but which can not scroll. Pls help me....

Main layout

<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent"
    android:background="#efefef"
    tools:context=".MainActivity">

    <include layout="@layout/conten_main" />

    <include layout="@layout/layout_bottom_sheet" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@drawable/air" />
</androidx.constraintlayout.widget.ConstraintLayout> 

I want to know how to Scroll in RecyclerView

Try this custom view

package com.avatus.util

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.LinearLayout


class DisallowInterceptView : LinearLayout {
constructor(context: Context?) : super(context) {
    requestDisallowInterceptTouchEvent(true)
}

constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
    requestDisallowInterceptTouchEvent(true)
}

constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
    context,
    attrs,
    defStyleAttr
) {
    requestDisallowInterceptTouchEvent(true)
}

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
    parent.requestDisallowInterceptTouchEvent(true)
    return super.dispatchTouchEvent(ev)
}

override fun onTouchEvent(event: MotionEvent): Boolean {
    when (event.action) {
        MotionEvent.ACTION_MOVE -> requestDisallowInterceptTouchEvent(true)
        MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> requestDisallowInterceptTouchEvent(
            false
        )
    }
    return super.onTouchEvent(event)
}
}

 <com.avatus.util.DisallowInterceptView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:padding="@dimen/_16sdp"
    android:background="#17141A"
    android:layout_height="match_parent">
    // Your view here 
</androidx.constraintlayout.widget.ConstraintLayout>

 </com.avatus.util.DisallowInterceptView>

I had the same requirement and solved it like below

Make BottomSheetDialog object attribute set cancelable false like below

viewIndentItemBottomSheetDialog.setCancelable(false)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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