簡體   English   中英

如何刪除Android復選框的內部圖像填充(頂部,左側和底部)

[英]How to remove internal Image padding (Top, Left and Bottom) of an Android Checkbox

我在Android上有一個Checkbox,上面有一個TextView:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="@dimen/default_margin">

    <TextView
        android:id="@+id/tv_edit_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:layout_margin="0dp"
        android:gravity="center_vertical|center_horizontal"
        android:text="@string/edit_checkbox" />

    <CheckBox
        android:id="@+id/cb_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:checked="true" />

</LinearLayout>

然而,Checkbox的問題在於它的內部“圖像”周圍有一個看不見的邊框。 如何刪除? 我已經嘗試過android:padding="-5dp"但這只適用於CheckBox的右側,出於某種原因,而不是頂部,左側和底部(我的主要關注點是Top)。

以下是Eclipse Graphical Layout窗口中Checkbox的屏幕截圖:

選擇LineairLayout: 在此輸入圖像描述 選中復選框: 在此輸入圖像描述

在第二張圖片中,您可以看到Checkbox在您選擇它時會在其周圍添加一些填充。 我想刪除它(特別是在頂部),以便減少Text和Checkbox之間的空間。

這是我填充=“ - 5dp”時的圖片:

選中復選框: 在此輸入圖像描述

PS:如果有人知道只有一個Checkbox和它的Text-field的解決方案,那么我可以刪除LineairLayout和TextView,同時仍然在Checkbox上面的Text我也會很感激。 具有自定義樣式和文本的單個復選框比具有附加TextView的LineairLayout內的復選框更適合於性能。 (我知道這更像是一個不同的問題,但我只是在這里添加它,因為它沒有很多優先級。除了Checkbox的填充之外,一切都已經工作了。)

好吧,我將LineairLayout更改為RelativeLayout,而且我可以將邊距更改為減去dp。 這是我的最終結果:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="@dimen/default_margin">

    <TextView
        android:id="@+id/tv_edit_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:singleLine="false"
        android:gravity="center_horizontal"
        android:text="@string/edit_checkbox" />

    <CheckBox
        android:id="@+id/cb_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_edit_checkbox"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-10dp"
        android:checked="true" />

</RelativeLayout>

這給出了以下結果:

RelativeLayout選擇: 在此輸入圖像描述

這確實會改變Text和Checkbox之間的空間。 對我來說這就是我想要的,但它仍然無法解釋為什么Android Checkbox的內部圖像在其頂部,左側和底部都有填充物。現在想知道Android有誰有這個想法,但它是一個非常糟糕的一個..最好只在內部圖像上使用無填充,然后有一些默認的內部邊距/填充,可由用戶更改..

要么

編輯:您還可以使用LinearLayout獲得相同的結果:

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:padding="0dp"
            android:text="For all products"
            android:textSize="10sp" />

        <CheckBox
            android:id="@+id/checkBox_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="-10dp"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1"
            android:padding="0dp" />
    </LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM