我正在尝试使用 wrap_content
让我的 Recycler View 在只有几个项目时不占用所有屏幕空间,但这似乎不起作用。有什么问题?
<?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
包装其内容。
关于Android - "wrap_content"不包装内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31939273/