met*_*ter 9 java xml layout android
我试图在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>
Run Code Online (Sandbox Code Playgroud)
这基本上完成了这项工作.但是,这四个图像中的每一个都在其上方和下方都有一个巨大的填充.我怎么摆脱它?或者我是否需要一起使用不同的布局类型?
为了帮助说明我的问题,这是一张图片.左边是我得到的,右边是我需要的. 图片
非常感谢你!
干杯,马库斯!
layout_weight从 TableRows 中删除并将其设置layout_height为wrap_content. 然后在它们下面添加一个空的 TableRow 并将其layout_height设置为fill_parent。