gpt4 book ai didi

android - 为什么观点分布不均

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

我有 4 个 TextView。我想要做的是让列表中的所有客人占用相同的空间(“VIP 列表”TextView 除外)。所以我将 layout_height 设置为 0dp,将 layout_weight 设置为 1,但底部仍有一些地方没有被占用。我的代码有什么问题?

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray">

<TextView
android:text="VIP List"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ACC1"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:gravity="center" />

<TextView
android:text="Bob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#BF360C"
android:textSize="24sp"
android:textColor="#FFFFFF"/>

<TextView
android:text="Bill"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#4CAF50"
android:textSize="24sp"
android:textColor="#FFFFFF"/>

<TextView
android:text="Ben"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#2E7D32"
android:textSize="24sp"
android:textColor="#FFFFFF"/>

</LinearLayout>

enter image description here

最佳答案

用这个改变你的LinearLayout代码;

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
android:background="@android:color/darker_gray">
...
</LinearLayout>

关于android - 为什么观点分布不均,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46587993/

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