gpt4 book ai didi

Android - "wrap_content"不包装内容

转载 作者:数据小太阳 更新时间:2023-10-29 02:49:46 25 4
gpt4 key购买 nike

我正在尝试使用 wrap_content 让我的 Recycler View 在只有几个项目时不占用所有屏幕空间,但这似乎不起作用。有什么问题?

enter image description here代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:weightSum="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/smoke_recycler_view"
android:scrollbars="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:paddingTop="4dp"
android:paddingRight="4dp"
android:paddingLeft="4dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:background="#FFF"
android:elevation="2dp" />
</LinearLayout>
</RelativeLayout>

最佳答案

最重要的是RecyclerView默认不支持wrap_content。您必须费些力气才能为它提供一个 LayoutManager,它可以强制您的 RecyclerView 包装其内容。

看看thisthis .

关于Android - "wrap_content"不包装内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31939273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com