如果使用paddingleft 处理checkbox 在显示上会有很大问题
解决方案
硬编码
CheckBox checkBox1 = new CheckBox(this);
checkBox1.setText("TEST CHECKBOX");
checkBox1.setButtonDrawable(android.R.color.transparent);// 设置它的button的图片为不可见
checkBox1.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null,null);// 设置右边图片
int px = UnitTransformUtil.dip2px(this, 10);
checkBox1.setCompoundDrawablePadding(px);// 图片和文本距离
xml:
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
androidutton="@null"
androidrawableLeft="@drawable/selector"
androidrawablePadding="10dp"
android:text="CheckBox" />
本文介绍了一种解决Checkbox在Android应用中布局偏移的方法,通过调整按钮样式和复合绘制间距实现正确的对齐效果。

482

被折叠的 条评论
为什么被折叠?



