Separate padding values for checkbox and text inside CheckedTextView

2.4k views Asked by At

Im trying to build my multiple choice layout according to latest material design guidelines with CheckedTextView widget. But I can't find the way to set left padding for checkbox and textview separately (16dp for icon, 72 for text). The most acceptable solution i could find is to use android:drawablePadding attribute but i think it is not quite right. Is it possible to set padding values separately inside CheckedTextView?

<?xml version="1.0" encoding="utf-8"?>

    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"

        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:gravity="center_vertical"
        android:textSize="16sp"
        android:textColor="#000000"
        android:paddingLeft="16dp"
        android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
        android:drawablePadding="36dp"/>
3

There are 3 answers

1
Bogdan Ilin On

I'm late to the party, but just in case someone is looking for a solution, here is how I did it using the CheckBox widget:

    <CheckBox
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:minHeight="30dp"
        android:textColor="#ffffff"
        android:layout_centerVertical="true"

        android:layout_marginStart="16dp"
        android:paddingStart="56dp"/>

android:layout_marginStart="16dp" sets margin to both icon and text, while android:paddingStart="56dp" sets padding between text and icon.

0
maxwellnewage On

Try this, it work for me, add a "padding" property:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:background="@color/grey"
android:textColor="@color/white"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:ellipsize="marquee"/>
0
Dimitri Hartt On
Try this one: (This is under RelativeLayout)

<CheckedTextView
    android:id="@+id/checkedTextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:text="@string/text"
    android:checkMark="?android:attr/textCheckMark"
    android:checked="false" />

It will stay like this:

Layout:
   |                                  |
   | Text for checkedTextView:      V |
   |                                  |