0

How can I have my checkbox aligned on the right and have the checkbox symbol after the text? I am targeting API 15 and above

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout1">
        <TextView
            android:text="@string/please_choose_an_area"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:id="@+id/textView2"
            android:textSize="20sp"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp" />
        <CheckBox
            android:text="All"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/checkBox1"
            android:layout_marginRight="15dp" />
    </LinearLayout>

4 Answers4

2

Add this 2 line of code with your CheckBox

android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"

Like this way .

<CheckBox
    android:text="All"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/checkBox1"
    android:layout_marginRight="15dp"
    android:button="@null"
    android:drawableRight="?android:attr/listChoiceIndicatorMultiple"/>
Zahidul Islam
  • 3,180
  • 1
  • 25
  • 35
2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal"
      android:gravity="center"
      android:weightSum="6"
      >
        <TextView
            android:text="place to select"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:id="@+id/textView2"
            android:textSize="20sp"
            android:layout_weight="5.8"
            android:layout_marginLeft="10dp" />
        <CheckBox
            android:layout_weight="0.2"
            android:text="All"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/checkBox1"
           android:gravity="right" 
            android:layout_marginRight="10dp"
            />
      </LinearLayout>
    </LinearLayout>
Nouman Shah
  • 534
  • 1
  • 9
  • 22
1

Use RelativeLayout inside LinearLayout like below

<RelativeLayout
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
      android:gravity ="end"
>

<TextView  
    android:id="@+id/text"
    android:text="myText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/chekcbox"
/>

<CheckBox 
    android:id="@+id/chekcbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"

 /> 

 </RelativeLayout>
Raghu Nagaraju
  • 3,278
  • 1
  • 18
  • 25
1

Try this code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="15dp"
        android:gravity="center"
        android:text="area"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="20sp" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="right|center_vertical"
        android:layout_marginRight="15dp"
        android:button="@null"
        android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
        android:text="All" />
</LinearLayout>
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58