相对布局与分组垂直对齐

时间:2012-09-02 10:03:50

标签: android view alignment relativelayout vertical-alignment

我有相对布局。我如何能够将垂直对齐分组:

http://s019.radikal.ru/i610/1209/a2/8dead85f60a3.jpg

2 个答案:

答案 0 :(得分:0)

我认为以下代码会有所帮助..

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

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:orientation="horizontal">

<TextView
    android:id = "@+id/Textview1"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    tools:context=".TestActivity" />

<EditText android:id="@+id/Editmessage1"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message" />

     </LinearLayout>

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_alignLeft="@+id/LinearLayout1"
android:layout_below="@+id/LinearLayout1"
android:orientation="horizontal">


<TextView
    android:id = "@+id/Textview2"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    tools:context=".TestActivity" />

<EditText android:id="@+id/Editmessage2"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message1" />



</LinearLayout>

      </RelativeLayout>

同样,添加另一个线性布局,它应该没问题。或者,您可以将“线性布局”的方向对齐为“垂直”,并将它们左右对齐。如果您正在使用Eclipse Emulator,我认为每次更改XML代码时,如果您参考图形设计会更容易。

有关对齐的更多信息,请参阅以下链接。

http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html

您可以根据需要改变重量。使textview变短并长时间编辑文本,反之亦然。

答案 1 :(得分:0)

谢谢,但我认为你的方式不适合我。我没有在图片中显示,但是一些edittext可以有多个行高。 现在我做了什么。我迭代所有文本视图,找到最大宽度并为它们设置这个宽度。

相关问题