【发布时间】:2018-10-24 18:10:52
【问题描述】:
我正在努力寻找解决方案。
基本上,我已经有了一个带有页眉和页脚的布局。我需要在剩余空间内放置 1 个 ListView 和 2 个 View,以便:
- ListView 从顶部开始并填满所有可用空间
- View1 就在 ListView 之后
- View2 在 View1 之后
- 如果 ListView 不可见(或很短),则应显示视图 位于屏幕顶部。
- ListView 应该扩展到 screen_heigth -header -footer -view1 -view2
我尝试了所有可能的链组合,将视图放在线性布局中,仅使用约束和偏差,但我得到的最接近的方法是以正确的顺序打包视图,但居中而不是在屏幕顶部。
<?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">
<View
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"/>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/view1"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintVertical_chainStyle="packed" />
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/view2"
app:layout_constraintTop_toBottomOf="@+id/list_view" />
<View
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/footer"
app:layout_constraintTop_toBottomOf="@+id/view1"/>
<View
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
谁能帮我解决这个问题?如有必要,我也可以将约束布局更改为其他内容
【问题讨论】:
标签: android listview android-constraintlayout