2012-02-10 97 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

相關問題