复选框右对齐

Checkbox align right

我怎样才能让我的复选框右对齐并在文本后面有复选框符号?我的目标是 API 15 岁及以上

<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>

将这两行代码添加到您的 CheckBox

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

像这样。

<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"/>

像下面这样在 LinearLayout 中使用 RelativeLayout

<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>

试试这个代码。

<?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>
<?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>