0

我想在代码中创建一个表格布局。每第 n 行应该是一个只有一个文本视图的标题。其他行应包含 3 个文本视图。当然,所有第一个、第二个和第三个视图应该是相同的宽度。

我现在的问题是第一列的宽度是由最广泛的 texview 设置的,它是标题,但对于其他行的第一个视图来说,这是很大的。所以我想组合标题所在行的单元格,这样它就可以跨越整行。其他单元格应该是最宽文本的大小。

这就是它的样子

______________________________
|Long Title__________________|
|x___|YYYY_____|ZZZ__________|
|XXX_|YYYYYYYYY|ZZZZ_________|
|xxxx|YYYYY____|ZZZ__________|
|xxx_|YY_______|Z____________|
|Long Title__________________|
|x___|YYYY_____|ZZZ__________|
|XXX_|YYYYYYYYY|ZZZZ_________|
|xxxx|YYYYY____|ZZZ__________|
|xxx_|YY_______|Z____________|

这就是它的外观

______________________________
|Long Title__________________|
|x_________|YYYY_____|ZZZ____|
|XXX_______|YYYYYYYYY|ZZZZ___|
|xxxx______|YYYYY____|ZZZ____|
|xxx_______|YY_______|Z______|
|Long Title__________________|
|x_________|YYYY_____|ZZZ____|
|XXX_______|YYYYYYYYY|ZZZZ___|
|xxxx______|YYYYY____|ZZZ____|
|xxx_______|YY_______|Z______|

如果有人可以帮助我,那就太好了。

4

1 回答 1

0

以下代码可以提供帮助。只需添加另一个线性布局块即可拥有 3 行。

    <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" >

<TextView
    android:id = "@+id/Textviewtitle"
    android:layout_width="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    tools:context=".TestActivity" />

<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="90dp"
     android:layout_alignLeft="@+id/Textviewtitle"
     android:layout_below="@+id/Textviewtitle"
     android:orientation="horizontal">

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
     android:layout_weight="1"
     android:layout_height="wrap_content"
     android:orientation="vertical">

 <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" />
 <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" />
 <TextView
    android:id = "@+id/Textview3"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    tools:context=".TestActivity" />



 </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_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">

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

</LinearLayout>

 </RelativeLayout>

使用以下链接获取有关对齐的更多参考。一旦添加了权重为 1 的第三个线性布局块,它将完美对齐。

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

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

重复同样的操作,您可以获得另外 3 个块行。

请看编辑。你可以使用这样的东西

于 2012-09-02T11:16:58.567 回答