2011-07-07 48 views
2

在我的應用程序中,我想在頁面的底部放置5個圖像按鈕。在5個按鈕中,我想要兩個按鈕位於屏幕的右側和左側角落,而一個按鈕正好位於屏幕的中央。另外兩個按鈕必須放置在這些按鈕之間,並且它們之間必須有相同的空間。我希望這是爲所有設備共同創建的。ImageButton在Android應用程序中的相對佈局問題

以下是我的佈局:

<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_height="wrap_content">  

    <RelativeLayout android:background="#ffffff" android:layout_width="fill_parent" android:layout_alignParentBottom="true" android:id="@+id/relativeLayout1" android:layout_height="wrap_content"> 
      <ImageButton android:layout_alignParentLeft="true" android:id="@+id/widget32" android:layout_width="wrap_content" android:background="@drawable/back" android:layout_height="wrap_content"> 
      </ImageButton> 

      <ImageButton android:layout_toRightOf="@+id/widget32" android:id="@+id/widget33" android:layout_width="wrap_content" android:background="@drawable/thumbsup" android:layout_height="wrap_content"> 
      </ImageButton> 

      <ImageButton android:layout_centerInParent="true"android:layout_toRightOf="@+id/widget33" android:id="@+id/flipme" android:layout_width="wrap_content" android:background="@drawable/flip" android:layout_height="wrap_content"> 
      </ImageButton> 

      <ImageButton android:layout_toRightOf="@+id/flipme" android:id="@+id/widget35" android:layout_width="wrap_content" android:background="@drawable/thumbsdown" android:layout_height="wrap_content"> 
      </ImageButton> 

      <ImageButton android:layout_alignParentRight="true" android:id="@+id/widget36" android:layout_width="wrap_content" android:background="@drawable/forward" android:layout_height="wrap_content"> 
      </ImageButton> 
    </RelativeLayout> 

    </RelativeLayout> 

我想設置的順序所有這些圖片,請幫助我。

現在我有一個新問題。我試着在1.5和2.1版本的設備上運行這段代碼。 在2.1中,佈局工作正常,但在1.5版本的設備中,按鈕呈鋸齒形。這是爲什麼?請幫幫我。

我無法將其更改爲任何其他佈局,因爲它會影響我的其他代碼。所以請給我一個相對佈局本身的解決方案。

+0

我的佈局的曲折形狀順序是這條線的第三個圖像按鈕「android:layout_centerInParent =」true「;」爲什麼這樣,任何人都可以解釋我..... –

回答

2

可以在相對佈局使用TableLayout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TableRow> 

     <ImageView 
      android:id="@+id/j_elective_02" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/aruba" 
      /> 
      <ImageView 
      android:id="@+id/j_elective_01" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/aruba"/> 

     <ImageView 
      android:id="@+id/j_elective_02" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/aruba" 
      /> 
      <ImageView 
      android:id="@+id/j_elective_01" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/aruba"/> 

     <ImageView 
      android:id="@+id/j_elective_02" 
      android:layout_width="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/aruba" 
      /> 
    </TableRow> 

</TableLayout> 
+1

是否有相對佈局的解決方案........ –

0

取而代之的將按鈕​​得到同樣的,把按鈕放在表格的佈局是這樣的......

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"   
     android:background="@drawable/bottom_bar" 
     android:stretchColumns="*">   
     <TableRow>   
     <Button 
      android:id="@+id/ImageButton1 " 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="ImageButton1 "> 
     </Button>   

     <Button 
      android:id="@+id/ImageButton2 " 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="ImageButton2 "> 
     </Button> 

     <Button 
      android:id="@+id/ImageButton3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="ImageButton3" 
      > 
     </Button> 

     <Button 
      android:id="@+id/ImageButton4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="ImageButton4" 
      > 
     </Button> 
     <Button 
      android:id="@+id/ImageButton5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="ImageButton5" 
      > 
     </Button> 
     </TableRow> 
</TableLayout> 

TableLayout中使用android:stretchColumns="*"將所有列對齊等間隔。

+1

有相對佈局的解決方案........ –