gpt4 book ai didi

android - 均匀占用空间的三元素LinearLayout

转载 作者:行者123 更新时间:2023-11-29 17:31:01 27 4
gpt4 key购买 nike

我想创建一个带有两个按钮和一个 ImageView 的水平线性布局,以便所有三个元素占据相同数量的空间。为此,我在所有三个中设置了 android:layout_weight="1"元素。我仍然看到所有三个元素占用的空间是不同的,中间元素的空间最大,第三个和第一个元素的空间最小。

<LinearLayout
android:id="@+id/footerpreview"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:visibility="visible"
>
<ImageView
android:id="@+id/face"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/face"
android:background="#2D4487"
android:gravity="center"
android:padding="10dp"
/>

<ImageView
android:id="@+id/gyee"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/gyee"
android:background="#469AEB"
android:gravity="center"
android:padding="10dp"
/>
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Submit"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
android:layout_gravity="center"
android:background="#F3931D"/>
</LinearLayout>

最佳答案

你只需要改变

android:layout_width="wrap_content"

android:layout_width="0dp"

对于所有三个 View,它们将被平均布局。

关于android - 均匀占用空间的三元素LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32995830/

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