我已經使用XML佈局創建器在LinearLayout(下面的XML中包含的XML)中使用RadioGroup在Android中創建了自定義圖標欄。 RadioGroup中的每個RadioButton都有一個自定義可繪製(帶有選中和未選中狀態)作爲其android:button
屬性。如何使用XML根據圖像大小調整Android組件的大小
線性佈局本身在RelativeLayout
之內,因此它可以出現在屏幕上的任意位置(在本例中爲側欄)。
繪圖寬55像素,所有這些視圖的android:layout\_width
屬性是wrap\_content
。
當我使這個組件可見時,與屏幕的左下角對齊,只有大約四分之三的RadioButton圖像寬度可見。將RelativeLayout
的layout\_width
設置爲fill\_parent
可解決此問題並導致出現完整按鈕。
但是這意味着按鈕組消耗整個屏幕寬度的點擊事件。
如何讓整個按鈕顯示,並且只有按鈕的區域響應點擊?對drawable的寬度進行硬編碼並不是特別理想的解決方案。
<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_below="@+id/LinearLayout01" android:visibility="invisible">
<RadioGroup android:id="@+id/RadioGroup01" android:layout_height="wrap_content" android:checkedButton="@+id/RB01" android:layout_width="fill_parent">
<RadioButton android:id="@+id/RB01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR01"/>
<RadioButton android:id="@+id/RB02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR02"/>
<RadioButton android:id="@+id/RB03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR03"/>
<RadioButton android:id="@+id/RB04" android:layout_width="fill_parent" android:layout_height="wrap_content" android:button="@drawable/DR04"/>
</RadioGroup>
</LinearLayout>
</RelativeLayout>
爲什麼55 dp?所有Android的寬度爲220dp? – Jaseem 2011-12-30 11:48:28