2010-05-16 54 views
8
對齊

我想對齊四個同樣大小的正方形在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> 

這基本上沒有工作但是,這四個圖像中的每一個上面都有巨大的填充,並在它如何擺脫這一點。 ?或者我需要使用不同的佈局類型?

爲了幫助說明我的問題,這裏有一張照片。 左邊是我得到的,右邊是我需要的。 Image

非常感謝!

乾杯,馬庫斯!

回答

3

從您的TableRows中移除layout_weight並將其layout_height設置爲wrap_content。然後在它們下面添加一個空的TableRow,並將layout_height設置爲fill_parent

+0

謝謝!這種使用fill_parent佈局的技巧就是我所期待的。 – metter 2010-05-17 17:01:02

0

嘗試使用scaleType作爲centerCrop,如果圖像尺寸較大,那麼這將爲你做詭計。但這不是最好的辦法,更好的辦法是改變圖像資源。

HTH!

+0

Hello Karan。 感謝您的提示。然而,我的描述似乎並不太清楚(尤其是圖片);我需要廣場保持正方形。它們應該在2x2網格中儘可能大。但屏幕上的剩餘空間不能在四個方格之間,而是在屏幕下方的空格之下。 你有指針嗎? 謝謝。 – metter 2010-05-16 13:27:45

0

嘗試將ImageView高度設置爲fill_parent,我認爲應該這樣做。無論如何,如果你的XML屬性被分成幾行,這將會有所幫助,但我們其他人很難閱讀一行屬性。

另外,你爲什麼要在LinearLayout中放置TableLayout?除非在Linear中有更多元素,否則可以將其除去。

+0

不幸的是,這並沒有達到預期的效果。謝謝你的時間! @代碼;你是對的。我現在已經將它重組爲幾行。 – metter 2010-05-17 17:00:39