Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove padding around Android CheckBox

I need to put check to the right hand top corner of my imageview. But when I do this I noticed a default margin around my checkbox. Is there a way to remove this??

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" >

        <ImageView
            android:id="@+id/thumbImage"
            android:layout_width="100dp"
            android:layout_height="132dp"
            android:layout_gravity="center" />
    </FrameLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="#ff0000"
        android:gravity="center" >

        <CheckBox
            android:id="@+id/itemCheckBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_gravity="center"
            android:button="@drawable/checkbox_background"
            android:paddingLeft="0dp"
            android:paddingTop="0dp" />

    </LinearLayout>

</RelativeLayout>
like image 280
Lincy Avatar asked Jan 24 '13 07:01

Lincy


4 Answers

There's now a better way of doing this:

android:minWidth="0dp"
android:minHeight="0dp"
like image 124
Rishabh876 Avatar answered Oct 20 '22 21:10

Rishabh876


To remove radio button default margins or padding in android

if you using xml

android:minWidth="0dp"
android:minHeight="0dp"

if using programmatically

 radiobtn.setMinimumHeight(0);
 radiobtn.setMinimumWidth(0);
like image 22
Abhishek Garg Avatar answered Oct 20 '22 22:10

Abhishek Garg


You could use a negative margin.

android:layout_marginTop = "-5dp"
android:layout_marginRight = "-5dp"
like image 29
Benito Bertoli Avatar answered Oct 20 '22 22:10

Benito Bertoli


This works for me in Constraint Layout. I hope it will work for another layout.

<androidx.appcompat.widget.AppCompatCheckBox
                ...
                android:translationX="-5dp"
                 />
like image 6
Shihab Uddin Avatar answered Oct 20 '22 22:10

Shihab Uddin