2014-01-07 2 views
1

Как мне создать Relative Layout, содержащий TextViews, как показано на рисунке ниже.Проектирование относительной компоновки

Я пытался во многих отношениях, но TextView2 не получал ниже TextView1.

Можно ли рисовать все текстовые объекты в пределах 1 относительной компоновки.

PS - Мне нужно использовать Relative Layout, как и использовать Right of.

Спасибо enter image description here

+0

Где именно у вас есть проблемы, макет очень просто сделать. – Luksprog

+1

Можете ли вы опубликовать, что вы сделали, потому что я не вижу проблемы с использованием 'layout_below' для второго текста. – Fllo

ответ

1

Что-то вроде этого:

  • TV2 - layout_below TV1 и выравнивать родитель оставил
  • TV3 - layout_below TV1 и право TV2
  • TV4 - layout_below TV2 и выравнивать родительский левый
  • TV5 - layout_below TV2 и справа от TV4
  • ТВ6 - layout_below TV4 и выравнивать родитель оставил
  • TV7 - layout_below TV4 и справа от ТВ6
1

Вы можете использовать LinearLayout с вертикальной ориентацией. TV1 - первый ребенок, с силой тяжести и шириной match_parent. TV2 и TV3 могут содержаться в LinearLayout с горизонтальной ориентацией и располагаться в соответствии с весом. Оставшиеся четыре TextView s могут быть подвергнуты аналогичной обработке.

1

Вот XML ... я надеюсь, что это будет полезно

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
<TextView android:id="@+id/TV1"/> 
<TextView android:id="@+id/TV2" 
      android:layout_below="@id/TV1" 
      android:layout_alignParentLeft="true"/> 
<TextView android:id="@+id/TV3" 
      android:layout_below="@id/TV1" 
      android:layout_alignRight="@id/TV2"/> 
<TextView android:id="@+id/TV4" 
      android:layout_below="@id/TV2" 
      android:layout_alignParentLeft="true"/> 
<TextView android:id="@+id/TV5" 
      android:layout_below="@id/TV2" 
      android:layout_alignRight="@id/TV4"/> 
<TextView android:id="@+id/TV6" 
      android:layout_below="@id/TV4" 
      android:layout_alignParentLeft="true"/> 
<TextView android:id="@+id/TV7" 
      android:layout_below="@id/TV4" 
      android:layout_alignRight="@id/TV6"/> 
</RelativeLayout> 
0

Попробуйте это:

enter image description here

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Text View 1" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp" 
     android:gravity="end" /> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Text View 2" 
     android:layout_marginTop="25dp" 
     android:layout_marginLeft="20dp" 
     android:textSize="20sp" 
     android:gravity="start" /> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="25dp" 
     android:text="Text View 3" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp" 
     android:gravity="end" /> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Text View 4" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="55dp" 
     android:textSize="20sp" 
     android:gravity="start" /> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="55dp" 
     android:text="Text View 5" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp" 
     android:gravity="end" /> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Text View 6" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="85dp" 
     android:textSize="20sp" 
     android:gravity="start" /> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="85dp" 
     android:text="Text View 7" 
     android:layout_marginRight="20dp" 
     android:textSize="20sp" 
     android:gravity="end" /> 
</RelativeLayout> 
Смежные вопросы