2010-08-09 42 views
1

我有4個按鈕排列在2x2 TableLayout中。這些按鈕每個都有左側的圖像和一些文字。這些按鈕在模擬器中可以很好地顯示1.5和2.2,但是當使用1.6進行測試時,右側列中的兩個按鈕會被裁剪掉,以致它們缺少右手邊緣(缺少文本右側的填充並且按鈕突然結束,而不是圓角)。 TableLayout有足夠的空間擴展以適應按鈕的全部寬度。這發生在所有屏幕尺寸上。TableLayout中的按鈕在Android 1.6和2.1(但不是1.5或2.2)上裁剪

佈局看起來像這樣與自身出現的RelativeLayout內:

<TableLayout android:id="@+id/buttons" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_alignParentTop="true" 
      android:paddingTop="10dp"> 
    <TableRow> 
    <Button android:id="@+id/button1" 
      style="@style/LaunchButton" 
      android:drawableLeft="@drawable/button1" 
      android:text="@string/button1"/> 
    <Button android:id="@+id/button2" 
      style="@style/LaunchButton" 
      android:drawableLeft="@drawable/button2" 
      android:text="@string/button2"/> 
    </TableRow> 
    <TableRow> 
    <Button android:id="@+id/button3" 
      style="@style/LaunchButton" 
      android:drawableLeft="@drawable/button3" 
      android:text="@string/button3"/> 
    <Button android:id="@+id/button4" 
      style="@style/LaunchButton" 
      android:drawableLeft="@drawable/button4" 
      android:text="@string/button4"/> 
    </TableRow> 
</TableLayout> 

的按鈕樣式如下:

<style name="LaunchButton"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:gravity">fill_horizontal</item> 
    <item name="android:textSize">24dp</item> 
    <item name="android:textStyle">bold</item> 
</style> 

我假設這是一個1.6特定錯誤。有其他人遇到這個問題嗎?任何關於解決方法的建議?

編輯:我有機會嘗試與Android 2.1(在模擬器和設備上),並且問題也發生在那裏。所以1.5好,1.6差,2.1差,2.2好。

+0

最簡單的變通現在是指定一個固定的按鈕的寬度,而不是將其設置爲「WRAP_CONTENT」,讓佈局數字出來。 – 2010-08-09 14:20:16

回答

1

我也碰到1.6和2.1相同的問題,但不是1.5或2.2。

我使用LineraLayout並設置它的重量,而不是使用TableLayout跳過問題。

<LinearLayout 
    android:orientation="horizontal" android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_weight="1" android:layout_height="wrap_content" 
     android:gravity="center"> 
     <ImageButton 
      android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_weight="1" android:layout_height="wrap_content" 
     android:gravity="center"> 
     <ImageButton 
      android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_weight="1" android:layout_height="wrap_content" 
     android:gravity="center"> 
     <ImageButton 
      android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
    </LinearLayout> 

相關問題