gpt4 book ai didi

android - ConstraintLayout 内的 ListView - 项目居中

转载 作者:行者123 更新时间:2023-11-29 16:41:15 26 4
gpt4 key购买 nike

我在 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);因为如果我删除它们,项目就会在顶部(但我的 ListView 会处于不利位置)。

我该如何解决?

最佳答案

设置 layout_height="0dp",这将设置它以匹配约束。

关于android - ConstraintLayout 内的 ListView - 项目居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50641106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com