RecycledView(wrap_content)在BottomSheetDialogFragment中

问题描述 投票:10回答:2

我在这里面临一个棘手的局面,我不知道如何解决这个问题。 在我的项目中,我有一个自定义的BottomSheetDialogFragment,并在布局中添加或替换FrameLayoutFragment

现在我有一个Fragment和里面我有一个RecyclerViewheight:="wrap_content"因为我希望BottomSheetDialogFragment只使用必要的空间。一切看起来都很棒,当我在同一布局中放置另一个视图并将该视图设置为低于或高于该视图时,问题就出现了。 RecyclerView忽略了其他视图(或视图)的大小,并且总是增长到最大屏幕大小,然后就不可能看到一些元素甚至滚动。

我看到一个RecyclerView,一些开发人员建议添加solution等于视图的高度。但在我的情况下不起作用,因为我想有一个动态的解决方案。

上面我将分享一些问题的图像和paddingBottom样本。

GitHub Repository enter image description here感谢您的关注!

android android-recyclerview bottom-sheet
2个回答
2
投票

我已经设法做你需要的只需要将它用作fragment_sample.xml:

enter image description here

说明使用LinearLayout可以使用权重,垂直方向允许您将项目放在另一个下面。 Recyclerview上的重量将根据需要增加其高度,直到填满屏幕。您添加的下一个项目将添加到recyclerview,但您需要滚动列表才能看到它


-1
投票

Android开发者博客说: -

底部工作表中的滚动容器必须支持嵌套滚动。

尝试更改你的<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rclItems" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> <Button android:id="@+id/btnAddMoreItems" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/rclItems" android:text="@string/add_1_item"/> </LinearLayout> 如下,使fragment_sample.xml滚动工作,并使添加按钮持久。

recyclerview

注意:使底部表格布局成为<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:id="@+id/next" android:layout_above="@id/btnAddMoreItems" android:layout_height="wrap_content"> <android.support.v7.widget.RecyclerView android:id="@+id/rclItems" android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.v4.widget.NestedScrollView> <Button android:id="@+id/btnAddMoreItems" android:layout_width="match_parent" android:layout_alignParentBottom="true" android:layout_height="wrap_content" android:text="@string/add_1_item"/> </RelativeLayout> 的子视图将允许您获得工具BottomSheetBehavior并接收其过渡回调。

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