2012-11-05 24 views
0

我試圖用4個單元格創建一個表格,每行有2個ImageButton。 出於某種原因,ImageButton似乎是寬和退出屏幕,即使tablerow寬度爲match parent在表中擬合ImageButton

下面的代碼:

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:layout_weight="1" > 
<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"  

    > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <ImageButton 
      android:id="@+id/button5" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/button4" 
      android:background="@null" 
      android:onClick="changepic2" 

      android:src="@drawable/breakingdawn" 
      android:text="Breaking Dawn" /> 

     <ImageButton 
      android:id="@+id/button4" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignBaseline="@+id/button1" 
      android:layout_alignBottom="@+id/button1" 
      android:layout_alignLeft="@+id/button5" 
      android:layout_alignParentRight="true" 
      android:background="@null" 
      android:onClick="changepic3" 

      android:src="@drawable/newmoon" /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <ImageButton 
      android:id="@+id/button1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/button3" 
      android:layout_alignParentLeft="true" 
      android:onClick="changepic" 

      android:paddingTop="2dp" 

      android:src="@drawable/twilight" 
      android:background="@null"/> 

     <ImageButton 
      android:id="@+id/button3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:onClick="changepic1" 

      android:src="@drawable/eclipse" 
      android:paddingTop="2dp" 
      android:background="@null" /> 
    </TableRow> 
</TableLayout> 

任何想法我如何使它完全適合屏幕?

謝謝! :)

+1

而是這個'的android:SRC = 「@繪製/月食」'使用'的android:背景= 「@繪製/月食」',並嘗試一次 – Zombie

回答

0

而不是

android:src="@drawable/eclipse"

使用android:background="@drawable/eclipse"

,並嘗試一次。它可以幫助你

,並使用wrapcontent代替matchparent

+0

謝謝但它沒有工作,仍然是相同的結果,在屏幕右側的按鈕退出屏幕 – Nadav

+0

你刪除了'android:background =「@ null」'這和上面的東西嘗試?因爲這對我有用 – Zombie

+0

是的,改變了它,它給出了和以前完全相同的結果 – Nadav