checkbox-padding 調整checkbox字體跟圖標距離


有時候我們會遇到需要調整控件中的內容相對於容器的位置。這里有兩種情況
1.linearlayout這樣的容器中,包含button類的控件,這時候margin可以調節
2.textview中的文字內容 今天想實現一個功能,就是在一個relativelayout里面放了兩個textview,但是這兩個textview里面字體大小有限制,而兩個字體 間距也有要求。因為relativelayout的大小是固定的,而textview里面內容跟textview又有變距。最終導致的結果就是,兩個的距 離始終沒辦法達到要求。
 嘗試1.relativelayout本身的控件是可以重疊的,所以使用marginBottom,而不處理兩個textview的相對位置
結果:失敗  因為如果不描述兩者之間的相對位置,那個textview就會置頂,如果添加了,就會在他的下面,無法調整到二者的距離很小
嘗試2.使用padding
結果:順利實現了,看了網上說的,感覺還是有點不對,padding更偏向於控件內容相對於控件邊緣的位置。我的之所以實現,是因為我把textview放到relativelayout里面了,這就能使textveiew的邊框非常大。

padding的另外一個用處就是:它可以調節checkbox文字跟圖片的內容,這個非常的實用的

代碼如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.text.MainActivity" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
    <CheckBox
        android:layout_below="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#0000ff"
        android:text="dddddd"
        android:paddingLeft="30dp"
        android:paddingRight="12dp"
        android:paddingTop="50dp"
        
        />

</RelativeLayout>

效果你會發現,圖標的位置沒有變化,變化的僅僅是文字。從而得出的 結論就是

checkbox中的padding針對的是text部分,而不是image

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM