相关疑难解决方法(0)

RecyclerView wrap_content 不工作。TextView 不显示后

我遇到了一个我无法解决的问题。我有一个CardView包含 a的片段RecyclerView。这RecyclerView有,layout_height="wrap_content"但我可以看到这是行不通的。我在这里阅读了一些解决方案,说在支持库的 23.2 版中这是固定的,但在我的情况下不起作用。另外,我想要一个在 的TextView正下方CardView,但它没有显示出来。如果我给CardView一个固定的高度,它工作正常。

我希望有人可以帮助解决这个问题。

编辑 让我们看看这张图片是否能更好地解释我的意思。

在此处输入图片说明

在这里,RecyclerView限制是蓝色矩形,而它们应该类似于红色矩形,这就是我想要归档的。

构建.gradle

dependencies{
          compile 'com.android.support:recyclerview-v7:24.+'
}
Run Code Online (Sandbox Code Playgroud)

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
          >
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:padding="5dp"
        card_view:cardElevation="4dp">
          <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipeContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.RecyclerView
               android:layout_width="match_parent"
               android:layout_height="wrap_content">
            </android.support.v7.widget.RecyclerView>

          </android.support.v4.widget.SwipeRefreshLayout>

    </android.support.v7.widget.CardView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:text="test text"
        android:textSize="20sp"/>
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

1
推荐指数
1
解决办法
3648
查看次数

标签 统计

android ×1

android-recyclerview ×1