web-dev-qa-db-ja.com

制約レイアウトでごみ箱の高さを「wrap_content」にする

私はwrap_contentでリサイクラビューの高さを設定し、それを尊重しようとしていますが、レイアウト上の他のウィジェットを超えます。今何ができますか?

<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>
21
ali samawi

私は同じ問題を抱えていて、この解決策を見つけました:recyclerviewにこの属性を追加する必要があり、constraint_layoutでrecyclerviewをwrap_contentにします:

app:layout_constraintHeight_default="wrap"

この解決策で問題が解決したかどうかをお知らせください。

編集:リサイクラーの高さは0dpでなければなりません。

編集2:サポートライブラリの新しいバージョンでは、このコードを使用します:

Android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
51
Reza.Abedini
app:layout_constraintHeight_default="wrap"

サポートライブラリの新しいバージョンでは廃止されているため、

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

代わりに。

11
JohnTheWalker