我在我的项目中使用了一个复选框,但是我不能去掉左边的填充,所以对齐不正确。

有谁知道如何消除左边的填充?
发布于 2015-05-07 15:37:17
经过一些研究,我发现,这个特定的边距是在方格的抽屉里。所以我想唯一的解决方案就是创建一个自定义的可绘制的
发布于 2015-05-07 15:42:12
这是因为Android使用的drawable复选框有自己的边距。因此,为了避免它,你必须创建你自己的复选框,带有自定义的可绘制和选中和未选中状态的图标。
1>为您的复选框创建一个自定义选择器,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/ic_unchecked" />
<item android:state_checked="true" android:drawable="@drawable/ic_checked" />
<item android:drawable="@drawable/ic_unchecked" /> <!-- default -->
</selector>2>Then在你的xml中添加一个普通的复选框,将drawable和button属性设置为null,并将选择器指定为checkbox.Also的左侧可绘制的,在复选框图标和文本之间提供一个可绘制的填充。
<CheckBox
android:id="@+id/chk_terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:button="@null"
android:drawableLeft="@drawable/custom_checkbox"
android:drawablePadding="@dimen/margin_left_right"
android:text="@string/i_agree"
android:textSize="@dimen/text_size_small"
/>备注->
这个解决方案还解决了Android4.2及以上版本的checkbox的填充问题。也称为HERE
https://stackoverflow.com/questions/30094026
复制相似问题