我已经使用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