gpt4 book ai didi

java - Android:四个正方形的对齐

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:16 24 4
gpt4 key购买 nike

我正在尝试在 Android 屏幕上对齐四个大小相同的正方形,我现在已经尝试了上百万种不同的方法,但它们似乎都不起作用:(。

我现在得到的是以下内容:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:id="@+id/MasterLayout" android:layout_width="wrap_content"     android:layout_height="fill_parent"  android:background="#FFFFFF">
<TableLayout android:layout_width="fill_parent" android:id="@+id/mainlay" android:background="#444444" android:layout_weight="0.2" android:layout_height="wrap_content" android:padding="0dip">
<TableRow android:layout_weight="1" android:background="#BBBBBB" android:padding="0dip">
<ImageView android:id="@+id/ImageView1" android:layout_marginLeft="10px" android:layout_weight="1" android:layout_marginRight="5px" android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="centerInside" android:src="@drawable/bigbox_new"></ImageView>
<ImageView android:id="@+id/ImageView2" android:layout_marginLeft="5px" android:layout_weight="1" android:layout_marginRight="10px" android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="centerInside" android:src="@drawable/bigbox_new"></ImageView>
</TableRow>
<TableRow android:layout_weight="1" android:padding="0dip">
<ImageView android:id="@+id/ImageView3" android:layout_marginLeft="10px" android:layout_weight="1" android:layout_marginRight="5px" android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="centerInside" android:src="@drawable/bigbox_new"></ImageView>
<ImageView android:id="@+id/ImageView4" android:layout_marginLeft="5px" android:layout_weight="1" android:layout_marginRight="10px" android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="centerInside" android:src="@drawable/bigbox_new"></ImageView>
</TableRow>
</TableLayout>
</LinearLayout>

这基本上完成了工作。然而,这四个图像中的每一个在其上方和下方都有一个巨大的填充。我该如何摆脱它?还是我需要同时使用不同的布局类型?

为了帮助说明我的问题,这里有一张图片。左边是我得到的,右边是我需要的。 Image

非常感谢!

干杯,马库斯!

最佳答案

从您的 TableRow 中删除 layout_weight 并将它们的 layout_height 设置为 wrap_content。然后在它们下面添加一个空的 TableRow,并将 layout_height 设置为 fill_parent

关于java - Android:四个正方形的对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2843087/

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