2014-01-07 79 views
1

如何設計包含TextViewsRelative Layout,如下圖所示。設計相對佈局

我嘗試了很多方法,但TextView2沒有低於TextView1

是否可以在1個相對佈局內繪製所有的TextView。

PS - 我必須使用Relative Layout,因爲必須使用Right。

謝謝 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的右側
  • TV6 - layout_below TV4和調整父離開
  • TV7 - layout_below TV4和TV6
1

您可以使用LinearLayout與垂直方向。 TV1是第一個孩子,地心引力正確且寬度爲match_parent。 TV2和TV3可以包含在水平方向的LinearLayout中,並根據重量進行定位。其餘四個TextView可能會被類似處理。

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>