2014-02-12 3 views
0

Я пытаюсь установить одно текстовое изображение влево, а другое вправо в горизонтальном linearlayout, которое вложено в вертикальный linearlayout, вложенный в scrollview. Горизонтальная линейная просадка выглядит так:Выравнивание слева направо в linearlayout

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 
<TextView android:id="@+id/txtType" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:text="Type of Event: " 
    style="@style/black_text_bold" 
    android:visibility="gone"/> 
<TextView android:id="@+id/outputType" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:text="Loading..." 
    style="@style/black_text" 
    android:visibility="gone"/>  
</LinearLayout> 

Как бы это согласовать? Я хочу txttype начать с левой и OutputType до конца по праву, как:

|       | 
| txtType:  outputType | 
|       | 

Спасибо заранее,

Тайлера

+0

использование layou_weights в текстовом виде. – njzk2

ответ

1

Используйте это ..

<LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
     > 
    <TextView android:id="@+id/txtType" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:layout_weight="1" 
     android:text="Type of Event: " 
     style="@style/black_text_bold" 
     android:visibility="gone"/> 

    <TextView android:id="@+id/outputType" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:text="Loading..." 
     android:layout_weight="1" 
     style="@style/black_text" 
     android:visibility="gone"/>  
     </LinearLayout> 
1

Вы можете использовать атрибут layout_gravity, чтобы установить, как ребенок должен располагаться в контейнере.

Ваш левый вид layout_gravity должен быть left, чтобы выровнять его с левым краем контейнера. Аналогично для правильного вида - layout_gravityright, чтобы выровнять его с правым краем контейнера.

2

вы можете просто использовать RelativeLayout и использование атрибутов alignParentLeft и alignParentRight вроде этого:

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
<TextView android:id="@+id/txtType" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_marginTop="10dip" 
    android:text="Type of Event: " 
    style="@style/black_text_bold" 
    android:visibility="gone"/> 
<TextView android:id="@+id/outputType" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:text="Loading..." 
    android:layout_alignParentRight="true" 
    style="@style/black_text" 
    android:visibility="gone"/>  
</RelativeLayout> 
1
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView android:id="@+id/txtType" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:layout_width="1" 
     android:text="Type of Event: " 
     style="@style/black_text_bold" 
     android:visibility="gone"/> 

    <TextView android:id="@+id/outputType" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:layout_width="1" 
     android:text="Loading..." 
     style="@style/black_text" 
     android:visibility="gone"/>  
</LinearLayout> 
1

В TextView XML с идентификатором андроида : id = "@ + id/outputType", изменить ** android: layout_width = "wrap_c ontent "** с android: layout_width =" 0dip " и установить android: layout_weight =" 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" > 

    <TextView 
     android:id="@+id/txtType" 
     style="@style/black_text_bold" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:text="Type of Event: " 
     android:visibility="gone" /> 

    <TextView 
     android:id="@+id/outputType" 
     style="@style/black_text" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:text="Loading..." 
     android:visibility="gone" /> 

</LinearLayout> 
Смежные вопросы