位于 BottomsheetFragment 内的 Fragment 内的 Recyclerview 不滚动?

问题描述 投票:0回答:4

我有一个 BottomsheetDialogFragment,它有一个普通的 Fragment,其中有一个 recyclerview。问题是我无法滚动回收器视图。

我想过使用 NestedScrollView 但我在片段内有搜索功能。当键盘弹出时,它工作正常,但一旦键盘隐藏,底页向下的过渡就不正常了。所以,我无法使用它。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/whitebackground"


    android:focusable="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/whitebackground"
        >



    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

在运行时,我正在膨胀包含回收器视图的布局。

android android-fragments scroll bottom-sheet android-nestedscrollview
4个回答
2
投票

您可以在片段或活动中使用 isNestedScrollingEnabled 属性。

recyclerOuter.isNestedScrollingEnabled = false

0
投票

您想要拦截recyclerview的触摸事件而不是BottomSheet布局。 默认情况下,当您触摸滚动时,事件会在底部布局中触发,而不是在回收器视图上触发。使用下面的代码强制拦截recyclerview的触摸事件

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerViewNotes"
        android:layout_width="match_parent"
        android:focusableInTouchMode="true"
        android:layout_height="match_parent"/>


recyclerViewNotes?.setOnTouchListener { v, event ->
            v.parent.requestDisallowInterceptTouchEvent(true)
            v.onTouchEvent(event)
            true
        }

0
投票

<?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_width="match_parent"
    android:nestedScrollingEnabled="true"
    android:layout_height="match_parent"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/_350sdp"
        android:orientation="vertical"
        android:background="@drawable/bottom_sheet_shapee"
        android:layout_gravity="bottom"
        >
        <View
            android:id="@+id/view"
            android:layout_width="@dimen/_70sdp"
            android:layout_height="@dimen/_7sdp"
            android:background="@drawable/view"
            android:layout_gravity="center"
            android:layout_marginVertical="@dimen/_10sdp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
        <com.mydroid.svg.print.craft.design.graphic.sticker.a_editScreen.viewPager.BottomSheetViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="8dp"
            android:theme="@style/CustomBottomSheetDialog"
            app:behavior_peekHeight="160dp"
            app:layout_behavior="@string/bottom_sheet_behavior"
            tools:ignore="UnusedAttribute">
            <com.google.android.material.tabs.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:elevation="4dp"
                app:tabIndicator="@null"
                android:theme="@style/TabLayout_Theme"
                app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
                app:tabMinWidth="@dimen/_100sdp"
                app:tabMaxWidth="@dimen/_100sdp"
                app:tabBackground="@drawable/tab_shape"
                app:tabSelectedTextColor="@color/white"
                app:tabMode="scrollable"
                app:tabTextColor="?colorOnSurface"
                app:tabRippleColor="@android:color/transparent"/>

        </com.mydroid.svg.print.craft.design.graphic.sticker.a_editScreen.viewPager.BottomSheetViewPager>
    </LinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

强文字


-1
投票

由于您的问题是从键盘开始的,您可以尝试将以下行添加到 AndroidManifest.xml 中的活动定义中。此行将确保当键盘弹出时您的视图不会调整大小。

<activity...
android:windowSoftInputMode="adjustResize"
.../>

您应该添加到您的协调器布局中

android:fitsSystemWindows="true"

© www.soinside.com 2019 - 2024. All rights reserved.