布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxHeight="280dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/line/>
<View
android:id="@+id/line"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="@color/black"/>
</android.support.constraint.ConstraintLayout>
我想最初“包装回收器视图内容”(高度),但它不能超过280dp.似乎android:maxHeight没有任何影响.
解决方法:
只要你的父布局是ConstraintLayout,你就可以只使用XML实现这一点,你好像是你的.对RecyclerView标记进行以下更改:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_default="wrap"
app:layout_constraintHeight_max="280dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/line/>
关键属性是这三个:
android:layout_height="0dp"
app:layout_constraintHeight_default="wrap"
app:layout_constraintHeight_max="280dp"
通常,在约束视图的两侧时,您只使用0dp维度,但实际上您所要做的就是提供足够的约束来定义视图大小(并且限制双方只是最简单的方法).将高度设置为“匹配约束”后,您可以将默认高度约束与最大高度约束相结合,以获得您正在寻找的内容.
请注意,您必须使用1.1版本的约束布局库.确保您的应用的build.gradle文件具有以下内容:
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta5'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。