我正在尝试在 wrap_content 上设置回收站 View 的高度并使其尊重这一点,但它会超过布局上的其他小部件。 我现在能做什么?
<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 在约束布局中:
app:layout_constraintHeight_default="wrap"
如果此解决方案解决了您的问题,请告诉我。
编辑:回收站的高度应该是 0dp。
编辑 2:在较新版本的支持库中,使用以下代码:
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
关于android - 在约束布局中使 RecyclerView 的高度为 "wrap_content",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42762494/