【发布时间】:2018-06-01 10:10:11
【问题描述】:
我在 ConstraintLayout 中定义了一个 ListView:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/lblTitlePlan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title"
android:textStyle="normal"
android:textSize="12dp"
android:padding="5dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<RelativeLayout android:id="@+id/layoutTopContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_light"
android:elevation="5dp"
android:paddingBottom="10dp"
android:paddingTop="5dp"
app:layout_constraintTop_toBottomOf="@id/lblTitlePlan"
>
...
</RelativeLayout>
<ListView
android:id="@+id/listContainers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:divider="@null"
android:dividerHeight="0dp"
android:paddingTop="80dp"
android:paddingBottom="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/layoutTopContainer"/>
</android.support.constraint.ConstraintLayout>
问题是当 ListView 中只显示几个项目时,它们是垂直居中的。我希望它们位于 listView 的顶部。 我认为问题来自似乎也适用于项目的约束(layout_constraintBottom_toBottomOf 和 layout_constraintTop_toBottomOf);因为如果我删除它们,这些项目就在顶部(但是我的列表视图位置不好)。
我该如何解决?
【问题讨论】:
标签: android listview android-constraintlayout