Android 为什么复选框和文本之间有间隙?

Android 为什么复选框和文本之间有间隙?,android,checkbox,Android,Checkbox,我使用图像作为复选框。 这是我正在使用的xml <CheckBox android:id="@+id/remember" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tableLayout1" android:button="@drawable/checkbox_selector"

我使用图像作为复选框。 这是我正在使用的xml

<CheckBox
    android:id="@+id/remember"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:layout_below="@+id/tableLayout1"
    android:button="@drawable/checkbox_selector"
    android:layout_marginLeft="52dp"
    android:text="@string/remember"
    android:textColor="#000000" />

我得到的图像和文本之间的差距(见下图),是默认值; 是否可以更改?如果可以,请告诉我必须添加什么属性

checkbox\u selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" 
    android:drawable="@drawable/checked" />
<item android:state_checked="false" 
    android:drawable="@drawable/un_checked" />
</selector>


请试试这个:

    <RelativeLayout  android:layout_width="wrap_content"
           android:layout_height="wrap_content" 
           android:gravity="center">
         <CheckBox
             android:id="@+id/checkBox1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:button="@drawable/checkbox_selector"
             android:text="" />
         <TextView
             android:id="@+id/textView1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Remember Me"
             android:layout_toRightOf="@+id/checkBox1"
             android:layout_centerInParent="true
             android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>


尝试搞乱复选框的android:paddingLeft属性


有关更多信息,请参阅本文:

使用下面的代码来缩小差距

 final float scale = this.getResources().getDisplayMetrics().density;
 checkBox.setPadding(checkBox.getPaddingLeft() - (int)(10.0f * scale + 0.5f),
    checkBox.getPaddingTop(),
    checkBox.getPaddingRight(),
    checkBox.getPaddingBottom());

您使用的是哪种布局?假设您使用的是相对(或)线性布局,请检查您使用的填充是什么。通过调整填充,我想你可以解决这个问题。我使用的是相对布局,但该布局没有填充。添加textview@NickCampion不过我还是得到了正确的答案。老实说,诊断这些问题的最好方法是在模拟器上打开应用程序,并连接到层次结构查看器。然后,您可以通过单击元素并打开和关闭为视图提供额外间距的“附加对象”来查看。我猜有两个问题。1) 当复选框基于视图中心对齐时,文本视图在文本基准基线上对齐,2)文本视图可能因重力或默认文本视图填充而倾斜。同样,验证所有这些的最简单方法是通过eclipse中内置的hierarchyviewer工具。