2010-08-09 21 views
0

我想讓我的佈局看起來像這樣。我已經嘗試過gridviews,表格佈局等等,但無法讓它看起來正確。我想要這樣的東西。Android:試圖獲得2x2圖像按鈕時使用什麼樣的最佳佈局?

的ImageButton ImageButton2

ImageButton3 ImageButton4

ImageView1 

ImageButton5 ImageButton6

ImageButton6 ImageButton7 ImageButton8(這些都是小圖標)

ImageButton9 (small donate button) 

我只是不能似乎想出如何讓佈局工作w ith imagebuttons。我應該使用什麼佈局?如果可能,你可以發佈xml佈局的示例代碼嗎?

回答

0

你可以做這樣的事情,雖然可能有另一種方式來做到這一點:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
    </LinearLayout> 

    <ImageView android:layout_width="wrap_content" android:src="@drawable/icon" 
    android:layout_height="wrap_content" android:layout_gravity="center"/> 

    <LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
    </LinearLayout> 

    <LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 
    </LinearLayout> 

    <ImageView android:layout_gravity="center" android:src="@drawable/icon" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
</LinearLayout> 

這裏是結果。我扔了一個android項目,並使用默認圖標。

alt text

+0

我會看看那個,但我認爲imagebuttons搞的一團糟,由於大小...以及慣於線性佈局得到搞砸了不同的屏幕尺寸/密度? – 2010-08-09 15:16:16

+0

你認爲它可能集中這些? – 2010-08-09 16:07:09

+0

將按鈕居中?只需將android:layout_gravity =「center」添加到按鈕的線性佈局 – 2010-08-09 16:22:03

-1

也許這可以幫助你:

DroidDraw - 用戶界面(UI)設計/編輯器進行編程與Android

您可以使用圖形化編輯器,讓您的佈局,並生成XML。

+0

我已經試過DroidDraw但沒有多少運氣 – 2010-08-09 15:12:38

相關問題