【问题标题】:Recyclerview inside a Fragment which is inside BottomsheetFragment not scrolling?在 BottomsheetFragment 内的 Fragment 内的 Recyclerview 不滚动?
【发布时间】:2019-05-24 11:24:24
【问题描述】:

我有一个 BottomsheetDialogFragment,它有一个普通的 Fragment,它有一个 recyclerview。问题是我无法滚动 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>

在运行时,我正在膨胀包含 recyclerview 的布局。

【问题讨论】:

  • 您是否尝试过让滚动视图的“fillviewport”属性为真并导致回收器视图启用嵌套滚动?在设置 recyclerview 适配器 ViewCompat.setNestedScrollingEnabled(recyclerView, false); 后立即使用此行
  • 添加recyclerview后是否尝试过验证相关布局?
  • 你能定义什么是not okay吗?视频会很有帮助。
  • 我已经完成了滚动部分,但现在出现了新错误。我将recyclerview的高度设置为500dp左右。底部有一个空间,recyclerview 向上移动到屏幕顶部。
  • @Sniper 嘿,请分享您的解决方案或提供对答案的反馈。否则,任何访问此问题的人都会空手而归。社区试图帮助您,请提供帮助。

标签: android android-fragments scroll bottom-sheet android-nestedscrollview


【解决方案1】:

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

recyclerOuter.isNestedScrollingEnabled = false

【讨论】:

    【解决方案2】:

    由于您的问题从键盘开始,您可以尝试在 AndroidManifest.xml 中的活动定义中添加以下行。此行将确保当键盘弹出时您的视图不会调整大小。 <activity... android:windowSoftInputMode="adjustResize" .../>

    你应该添加到你的协调器布局中 android:fitsSystemWindows="true"

    【讨论】:

      【解决方案3】:

      您想为 recyclerview 而不是 BottomSheet 布局拦截触摸事件。 默认当您触摸滚动底部布局中的事件触发器时,不在 recyclerview 上。使用以下代码强制拦截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
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-03
        • 2020-06-01
        • 2023-04-05
        • 1970-01-01
        • 2020-12-23
        • 2020-09-07
        • 2016-03-07
        • 2019-05-25
        相关资源
        最近更新 更多