Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AppCompatCheckbox padding/margin/gravity

I have a AppCompatCheckBox in my layout. This is how it looks like:

enter image description here

The problem is the padding or margin or gravity is not the way I want it to be. There is a small gap between the Box and the left border. I set gravity to left/start paddding and margin to 0 but the gap still exists. How can I remove this? I want it to be completely at the left border or centered. Both would be okay. But set gravity to center does not work, too.

Anyone has an idea?

The CheckBox and the Text should be above each other.

<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>
like image 535
L3n95 Avatar asked Oct 20 '25 14:10

L3n95


1 Answers

Set Checkbox minWidth and minHeight value to Zero

checkbox.setMinWidth(0);
checkbox.setMinHeight(0);

or via xml

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp" />
like image 65
ucMedia Avatar answered Oct 22 '25 04:10

ucMedia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!