2016-04-28 2 views
0

Как я могу установить флажок справа от него и иметь символ флажка после текста? Я нацеливание 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> 
+1

Проверить, если вы можете использовать 'CheckedTextView'. – jaibatrik

+0

проверить это http://stackoverflow.com/questions/3156781/how-to-show-android-checkbox-at-right-side – Amy

ответ

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

Я думаю, что не нужно брать вложенный «линейный макет», поскольку он выполняется только с помощью одного «линейного макета», как в моем ответе. –

+0

@nostradamus, Как это будет принятый ответ? –

2

Добавить 2 строки кода с вашим 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"/> 
+0

приятно, но теперь, как я могу выровнять по правому краю? – Nostradamus

+0

добавить это 'android: gravity =" right | center_vertical "' –

+1

да, вместо добавления текстового просмотра отдельно это хороший путь! –

1

Использование RelativeLayout внутри LinearLayout, как показано ниже

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

Попробуйте этот код.

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

'android: layout_gravity =" right | center_vertical "' должен быть 'android: gravity =" right | center_vertical "', потому что 'layout_width'' match_parent' –

+1

@ZahidulIslam Mistaken Я отредактировал для получения справки. –

+0

Оцените с помощью Upvote, если это полезно :). –

Смежные вопросы