2015-09-03 2 views
1

Я хочу присвоить флажкам в виде списка в правой части экрана.Выровнять по правому флангу с правой стороны в виде списка

мой макет показан ниже

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="9" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/nameTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Name" 
     android:textSize="30sp" /> 

    <TextView 
     android:id="@+id/numberTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Number" 
     android:textSize="25sp" /> 

</LinearLayout> 

<CheckBox 
    android:id="@+id/checkBox" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right|center" 
    android:layout_weight="2" 
    android:gravity="right|center" /> 

Но когда я запускаю это я получаю результат, как флажки рядом с TextView

Output of code

Найдено ошибка .. его в mainactivity .. Я поставил ширину listview в качестве содержимого оболочки вместо заполнения родителем

+1

вес макета положить 1 к вашей линейной компоновке над флажком и удалите вес с флажка ставит фиксированную шириной – Pavan

+0

@Pavan ее не работает .. весь TextViews стать затененным и я могу даже видеть флажок –

+0

вы добавили фиксированную ширину к флажку проверить мой обновленный ответ, который вы можете изменить согласно вашему требованию – Pavan

ответ

1
 <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/nameTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Name" 
      android:textSize="30sp" /> 

     <TextView 
      android:id="@+id/numberTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Number" 
      android:textSize="25sp" /> 

    </LinearLayout> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     /> 
</LinearLayout> 
+1

Не работает я не могу видеть флажки –

2

Используйте RelativeLayout для раздела ChechBox и добавьте android:layout_alignParentRight="true". Попробуйте этот способ, позвольте мне сообщить.

Хорошо, вы можете установить 2 Textview и ChechBox в той же строке, используя макет (Linear Layout). И установите гравитацию, макет гравитации для ChechBox.

+1

Помещение флажка внутри относительного расположения делает все это неработоспособным. –

+0

Обновите свои ответы –

+0

Не могли бы вы показать мне, как, отредактировав мой код, показанный выше ... –

0

Проверить это один

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/nameTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Name" 
      android:textSize="30sp" /> 

     <TextView 
      android:id="@+id/numberTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Number" 
      android:textSize="25sp" /> 

    </LinearLayout> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="25dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right|center" 
     android:layout_marginRight="2dp" 
     android:gravity="right|center" /> 
    </LinearLayout> 
Смежные вопросы