滚动时防止 Recycler 的父级折叠
Posted
技术标签:
【中文标题】滚动时防止 Recycler 的父级折叠【英文标题】:Prevent Parent of Recycler From Collapse When Scrolling 【发布时间】:2020-09-05 10:24:55 【问题描述】:当我在回收站视图中滚动时,我遇到了一个回收站视图的父级崩溃的问题。我希望“父级”在滚动回收站视图时不会崩溃。我尝试使用android:nestedScrollingEnabled="false"
,但这不起作用。任何援助将不胜感激。
xml
<?xml version="1.0" encoding="utf-8"?>
<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_
android:layout_
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_
android:layout_
android:background="@color/green">
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottomSheetLayout"
android:layout_
android:layout_
android:background="@drawable/bottom_sheet_background_drawable"
android:elevation="25dp"
app:behavior_hideable="false"
app:behavior_peekHeight="65dp"
app:layout_behavior=".CustomSheetBehavior">
<RelativeLayout
android:layout_
android:layout_
android:layout_margin="8dp"
android:background="@drawable/back_white"
android:id="@+id/ll_search">
<EditText
android:layout_
android:layout_
android:id="@+id/et_search"
android:textSize="14sp"
android:layout_marginTop="15dp"
android:background="@drawable/custom_search2"
android:drawableStart="@android:drawable/ic_menu_search"
android:drawablePadding="6dp"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_margin="8dp"
android:layout_
android:layout_
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ll_search"
tools:listitem="@layout/item_bottom_sheet_recycler_view">
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
【问题讨论】:
【参考方案1】:解决方案是在
中使用recyclerView.stopNestedScroll()
recyclerView.setOnTouchListener(OnTouchListener v, event ->
)
【讨论】:
以上是关于滚动时防止 Recycler 的父级折叠的主要内容,如果未能解决你的问题,请参考以下文章