我遇到了使用 ConstraintLayout 与兼容工具栏重叠 ListView 的问题
我想做的就是有一个工具栏,然后在其余空间中有一个列表视图。很简单
这是我的布局
<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.Toolbar
android:id="@+id/app_toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Toolbar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:visibility="visible"
app:layout_constraintTop_toTopOf="parent"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_toolbar2"
/>
</android.support.constraint.ConstraintLayout>
我不确定问题是否出在 ListView 上layout_height
优先于其他所有内容,因此要使 ListView 与父级一样高,确保底部存在重叠或截断,因为工具栏占用了一些空间。
让 ListView 占据工具栏之后剩余的垂直空间的正确方法是什么?
根据官方文档约束布局 https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html#DimensionConstraints :
- 你需要使用
MATCH_CONSTRAINT
(0dp) 而不是 MATCH_PARENT
重要提示:不建议将 MATCH_PARENT 用于包含在
约束布局。类似的行为可以通过使用来定义
MATCH_CONSTRAINT 与相应的左/右或上/下
约束设置为“父”。
只需更改 Listview 宽度和高度 ="0dp"
<ListView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_toolbar2"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)