使RecyclerView的高度达到"wrap_content";在约束布局中 [英] make RecyclerView's height to "wrap_content" in Constraint layout

查看:435
本文介绍了使RecyclerView的高度达到"wrap_content";在约束布局中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在wrap_content上设置回收器视图的高度,并使其尊重这一点,但是它将超过布局上的其他小部件. 我现在该怎么办?

i'm trying to set the height of recycler view on wrap_content and make it respect that,but it will exceed the other widget on layout. what can i do now?

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white">



    <TextView
        android:id="@+id/tvPastRounds"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="0dp"
        android:text="Past Rounds"
        android:textColor="@color/text_color_black"
        android:textSize="16sp"
        app:layout_constraintLeft_toLeftOf="parent"/>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="24dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="16dp"
        android:clipChildren="true"
        android:maxHeight="150dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="@+id/tvPastRounds"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvPastRounds" app:layout_constraintVertical_bias="0.0"/>
</android.support.constraint.ConstraintLayout>

推荐答案

我遇到了同样的问题,并且找到了以下解决方案: 您应该将此属性添加到您的recyclerview中,并使您的recyclerview wrap_content在constraint_layout中:

i had the same issue and i find this solution: you should add this attribute to your recyclerview and it makes your recyclerview wrap_content in the constraint_layout:

app:layout_constraintHeight_default="wrap"

让我知道此解决方案是否可以解决您的问题.

let me know if this solution fixed your problem.

回收站的高度应为0dp.

EDIT : recycler's height should be 0dp.

在较新版本的支持库中,使用以下代码:

EDIT 2 : in the newer versions of support library, use this code:

android:layout_height="wrap_content"
app:layout_constrainedHeight="true"

这篇关于使RecyclerView的高度达到"wrap_content";在约束布局中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆