2011-12-14 2 views
0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/groups_massegesTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView" 
     android:layout_marginBottom="20dp" 
     android:layout_marginTop="20dp" 
     android:layout_marginLeft="10dp" 
     android:textColor="@color/list_text_color" /> 

    <CheckBox 
     android:id="@+id/groups_massegescheckBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/checkbox_background" 
     android:button="@drawable/checkbox" 
     android:focusable="false" 
     android:layout_marginBottom="20dp" 
     android:layout_marginTop="20dp" 
     android:layout_marginRight="5dp" 
     android:layout_gravity="right" 
     /> 
</LinearLayout> 

Я использую linearlayout, и я хочу установить флажок в правой части экрана. Я не хочу использовать relativelayout. Есть ли способ сделать это в linearlayout. Флажок всегда справа от textView.Как установить флажок в правой части экрана

ответ

5

Применить android:layout_weight="1" к TextView.

+0

Спасибо очень!!! – fish40

1

Во-первых, почему вы не хотите использовать RelativeLayout?

Во-вторых, в случае, если вы хотите это сделать, тогда просто поставьте layout_width="fill_parent" на этот флажок!

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="check box"  
    /> 
<CheckBox 
    android:id="@+id/checkBox1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right" 
> 
</CheckBox> 
</LinearLayout> 
0

У меня есть предложения этого типа проблемы, и я решил свою проблему, добавив weighSum как 2 на LinearLayout, то я поставил мой TextView-х layout_weight до 2 и чекбокс-х layout_weight до 0

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="10dp" 
android:orientation="horizontal" 
android:weightSum="2"> 

<TextView 
    android:id="@+id/groups_massegesTextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" 
    android:layout_marginBottom="20dp" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="10dp" 
    android:textColor="@color/list_text_color" 
    android:layout_weight="2" /> 

<CheckBox 
    android:id="@+id/groups_massegescheckBox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/checkbox_background" 
    android:button="@drawable/checkbox" 
    android:focusable="false" 
    android:layout_marginBottom="20dp" 
    android:layout_marginTop="20dp" 
    android:layout_marginRight="5dp" 
    android:layout_gravity="right" 
    android:layout_weight="0" 
    /> 

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