我想在RadioButton
和CheckBox
视图的左侧/开始添加填充。这样做的动机是要有全宽的可选列表(用于选择一个并选择多个),其中单选按钮或复选框元素在其自身和屏幕边缘之间有间隔,但不要以该间隔为不可单击的区域结尾是。
对于API 16及以下版本,我可以添加间距并保持可点击性,可以使用视图的paddingLeft
属性。对于API 17及更高版本,此属性控制button / box元素及其对应的文本之间的填充(当然,我们也要控制它)。
对于API 21及更高版本,我可以像这样使用可绘制的插图来创建所需的布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatRadioButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/margin_standard"
android:button="@drawable/inset_radio_button"
tools:text="Option A">
</androidx.appcompat.widget.AppCompatRadioButton>
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="?android:attr/listChoiceIndicatorMultiple"
android:insetLeft="@dimen/margin_standard" />
但这似乎最终抵消了点击反馈(波动)。有几个问题:
- 是否有更好的方法在所有(16个及以上)API级别上创建此间距?
- 如果对1)没有希望,是否有更好的方法为API 21及更高版本创建此间距,而不会与纹波反馈混淆?
- 如果对于1)或2)没有希望,那么最创造性的解决方案是什么?例如,这些视图左侧的一个视图向其传播触摸事件,或者是一个带有填充的容器,其作用相同。