我使用XML布局创建器在Android中创建了一个自定义图标栏,其中包含一个RadioGroup和一个LinearLayout(下面附有XML)。RadioGroup中的每个RadioButton都有一个自定义的drawable作为其android:button属性(具有选中和未选中状态)。
LinearLayout本身位于RelativeLayout中,以便可以出现在屏幕上的任意位置(例如侧边栏)。
这些可绘制对象的宽度为55像素,所有这些视图的android:layout_width属性均为wrap_content。
当我将此组件设置为可见并与屏幕底部左对齐时,只有大约四分之三的RadioButton图像宽度可见。将RelativeLayout的layout_width属性设置为fill_parent可以纠正此问题并导致整个按钮显示。
但是,这意味着按钮组跨越整个屏幕消耗点击事件。
如何使整个按钮出现,并且仅有按钮区域响应点击?硬编码可绘制对象的宽度不是特别理想的解决方案。
LinearLayout本身位于RelativeLayout中,以便可以出现在屏幕上的任意位置(例如侧边栏)。
这些可绘制对象的宽度为55像素,所有这些视图的android:layout_width属性均为wrap_content。
当我将此组件设置为可见并与屏幕底部左对齐时,只有大约四分之三的RadioButton图像宽度可见。将RelativeLayout的layout_width属性设置为fill_parent可以纠正此问题并导致整个按钮显示。
但是,这意味着按钮组跨越整个屏幕消耗点击事件。
如何使整个按钮出现,并且仅有按钮区域响应点击?硬编码可绘制对象的宽度不是特别理想的解决方案。
<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>