2012-02-10 104 views
3

我正在使用图像复选框。 这是XML我是uisng,为什么我在复选框和文本之间有空隙?

<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_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> 

enter image description here

+0

哪种布局您正在使用?假设您使用相对(或)线性布局,请检查您使用的填充项是什么。通过调整填充,我想你可以解决这个问题。 – kosa 2012-02-10 04:30:54

+0

我正在使用相对布局,但没有填充该布局.. – 2012-02-10 04:33:46

+0

添加文本视图的定义 – 2012-02-10 04:40:24

回答

0

请试试这个:::::

<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> 
2

使用缩小差距

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

完美的作品! – 2015-12-15 11:34:01

相关问题