Android - "wrap_content"不包装内容

标签 android xml layout

我正在尝试使用 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/

相关文章:

java - 使用 Java 访问深层 XML 结构

css - 有没有可能的CSS技巧

java - 布局未显示为图形布局中所示?

java - 在 Android webview 中显示 Unicode 字符

java - 如何使用 XSD 验证 XML?

带有 Switch onCheckedListener 的 Android ListView 很奇怪

java - Android XML Web 服务用户名和密码验证

javascript - 函数 getelementbyid 没有输出到正确的位置

Android调试只报错

android - REST Web 服务的 SSL 证书(由 Android 使用)?