[英]RecyclerView on Bottom sheet can not scroll?
I want to recyclerView on Bottom sheet can scroll but i cant.我想底部工作表上的 recyclerView 可以滚动,但我不能。 I try use OntouchListenner in RecyclerView but which can not scroll.我尝试在 RecyclerView 中使用 OntouchListenner 但无法滚动。 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我想知道如何在 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使 BottomSheetDialog object 属性设置为可取消的 false,如下所示
viewIndentItemBottomSheetDialog.setCancelable(false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.