0

我在 LinearLayout 中有一个带有 RecyclerView 的布局,它也在自定义 NestedScrollView 中。在 api 21 和 22 中,布局看起来应该显示 RecyclerView 的所有元素,但在 api 23 及更高版本中,仅显示一两个项目,而屏幕的其余部分为空白。我知道 RecyclerView 的重点是不使用 wrap_content,但我的理解是你可以。

我注意到,当 RecyclerView 上方的视图可见时,recyclerview 上的 wrap_content 可以正常工作,但在特定情况下,我遇到的问题是这些视图都以编程方式设置为消失,所以它似乎与此有关。所以我不知道该怎么做,因为这些观点应该已经消失了。这是我无法解决的android sdk错误吗?

<CustomNestedScrollView
                    android:id="@+id/editProfileScroll"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scrollbars="vertical">

                    <LinearLayout
                        android:id="@+id/editProfileMainContainer"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/material_baseline_grid_10x"
                        android:orientation="vertical">

                        <!-- More code: TextViews and TextViews inside LinearLayouts -->

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/editProfileFieldsRV"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                    </LinearLayout>

                </CustomNestedScrollView>
4

1 回答 1

0

尝试使用 aRelativeLayout而不是 a LinearLayout


LinearLayout你将不得不设置

android:orientation="vertical"
android:weight_sum="3"

并且在每个元素中你必须添加android:layout_weight="1".

通过执行上述操作,它将在垂直轴上均匀放置 3 个项目。

于 2019-05-20T14:56:05.523 回答