0

我有相对布局。我如何进行分组垂直对齐:

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

4

2 回答 2

0

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

于 2012-09-02T20:50:13.607 回答
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 短而编辑文本长,反之亦然。

于 2012-09-02T10:47:13.073 回答