2016-12-06 45 views
1

我的佈局中有一個AppCompatCheckBox。這是它的樣子:Android AppCompatCheckbox填充/邊距/重力

enter image description here

問題是填充或保證金或重力是不是我希望它的方式。 Box和左邊框之間有一個小小的差距。我將重力設置爲左/開始paddding和餘量爲0,但差距仍然存在。我該如何刪除它?我希望它完全處於左邊界或居中。兩者都可以。但是,將重心設置爲中心也不起作用。

任何人有一個想法?

複選框和文本應該在彼此之上。

<LinearLayout 
      android:id="@+id/llRoot" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:id="@+id/llCbs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <android.support.v7.widget.AppCompatCheckBox 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:textColor="?attr/textColor" /> 

       <android.support.v7.widget.AppCompatCheckBox 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:textColor="?attr/textColor" /> 

       <android.support.v7.widget.AppCompatCheckBox 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:textColor="?attr/textColor" /> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/llTv" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" /> 
      </LinearLayout> 

     </LinearLayout> 
+0

請爲您提供佈局XML,這將幫助我們幫助您。 –

+0

這很可能是可繪製的內在填充;即盒子和圖像邊緣之間的空白空間。你可能可以在'View'上使用一個負的左/開始填充,但這真的很糟糕。處理它的最好方法可能是提供你自己的drawable。 –

+0

發佈您的* xml *代碼。 –

回答

0

你可以簡單地通過增加的LinearLayout設定在中心AppCompatCheckbox及其嚴重性設置爲中心並添加AppCompatCheckbox作爲其子。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 

     <android.support.v7.widget.AppCompatCheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 


</RelativeLayout> 
+0

不起作用。空間還在那裏。 – L3n95

+0

奇怪! @ L3n95它應該用於設置中心的複選框。它爲我工作。 –

0

這不是AppCompatCheckBox的問題,而是CheckBox本身的問題。我找到的唯一解決方案是設置負邊距(對於我來說-7dp非常好)。