2011-06-20 228 views
0

我的Android應用程序有兩個並排長度相同的圖像按鈕。他們填滿了一條線。 我打開手機,但imagebuttons沒有填滿線。 即使手機旋轉如何正確顯示? 感謝旋轉問題

回答

0

把這兩樣,如果它按預期工作中的TableRow &檢查按鈕後旋轉。

0

如果您使用的是水平佈局,請確保將寬度設置爲「fill_parent」,並且重量正確調整。

您還可以在onCreate中手動設置圖像按鈕的寬度。

1

使用線性佈局的weight屬性。將這兩個按鈕都放在內襯布局中,爲這兩個按鈕指定layout_width = odp和weight = 1。權重元素允許您指定每個元素將採用的寬度的比率。下面是一個簡單

<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content"      
    android:layout_alignParentBottom="true" android:layout_width="fill_parent"> 
    <Button android:text="Button" android:id="@+id/button1" 
    android:layout_height="wrap_content" android:layout_width="0dp" 
    android:layout_weight="1"> 
    </Button> 
    <Button android:text="Button" android:id="@+id/button2" 
    android:layout_height="wrap_content" android:layout_weight="1" 
    android:layout_width="0dp"> 
    </Button> 
</LinearLayout> 

編輯:樣本是一個按鈕,但你可以使用它的圖像按鈕太

+0

非常感謝您拉維,示例代碼工作。 – realuser

+0

我並不意味着粗魯無禮,但是當答案有用/正確時,您需要接受它並將其提升。 –