是否有一种简单的方法可以在复选框控件中的复选框和相关文本之间添加填充?
我不能只添加前导空格,因为我的标签是多行。
就像,文本太接近复选框了:
是否有一种简单的方法可以在复选框控件中的复选框和相关文本之间添加填充?
我不能只添加前导空格,因为我的标签是多行。
就像,文本太接近复选框了:
当前回答
我不知道,但我试过了
<CheckBox android:paddingLeft="8mm"并且只将文本向右移动,而不是整个控件。
它很适合我。
其他回答
我刚才的结论是:
覆盖CheckBox并添加此方法,如果你有一个自定义绘制对象:
@Override
public int getCompoundPaddingLeft() {
// Workarround for version codes < Jelly bean 4.2
// The system does not apply the same padding. Explantion:
// http://stackoverflow.com/questions/4037795/android-spacing-between-checkbox-and-text/4038195#4038195
int compoundPaddingLeft = super.getCompoundPaddingLeft();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Drawable drawable = getResources().getDrawable( YOUR CUSTOM DRAWABLE );
return compoundPaddingLeft + (drawable != null ? drawable.getIntrinsicWidth() : 0);
} else {
return compoundPaddingLeft;
}
}
或者如果你使用系统绘图:
@Override
public int getCompoundPaddingLeft() {
// Workarround for version codes < Jelly bean 4.2
// The system does not apply the same padding. Explantion:
// http://stackoverflow.com/questions/4037795/android-spacing-between-checkbox-and-text/4038195#4038195
int compoundPaddingLeft = super.getCompoundPaddingLeft();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
final float scale = this.getResources().getDisplayMetrics().density;
return compoundPaddingLeft + (drawable != null ? (int)(10.0f * scale + 0.5f) : 0);
} else {
return compoundPaddingLeft;
}
}
谢谢你的回答:)
我所做的,是有一个TextView和一个复选框内(相对)布局。TextView显示我想让用户看到的文本,而复选框没有任何文本。这样,我可以在任何我想要的地方设置复选框的位置/填充。
鉴于@DougW的响应,我所做的管理版本更简单,我添加到我的复选框视图:
android:paddingLeft="@dimen/padding_checkbox"
在两个值文件夹中找到dimen:
值
<resources>
<dimen name="padding_checkbox">0dp</dimen>
</resources>
values-v17 (4.2 JellyBean)
<resources>
<dimen name="padding_checkbox">10dp</dimen>
</resources>
我有定制check,用dps给你最好的选择。
如果您正在创建自定义按钮,例如,请参阅更改复选框的外观教程
然后简单地增加btn_check_label_background.9.png的宽度,在图像中心增加一到两列透明像素;让9个补丁标记保持原样。
我不知道,但我试过了
<CheckBox android:paddingLeft="8mm"并且只将文本向右移动,而不是整个控件。
它很适合我。