How to apply row_span to TableLayout?
I want to make something similar to this image, but i don't know how to do it.
What is the correct way to make something like this?
How to apply row_span to TableLayout?
I want to make something similar to this image, but i don't know how to do it.
What is the correct way to make something like this?
TableLayout
不支持行跨度,仅支持列跨度。GridLayout
支持行和列跨度:
(图片来自http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html)
小作弊(代码可能相当复杂,仅对简单设计有效):
做一个TableLayout
. 将另一个TableLayout
放在第一列和一个您希望在第二列中具有行跨度的视图。这个内部TableLayout
可以有尽可能多TableRows
的你希望另一个视图跨越。
这是代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin"
tools:context=".MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3">
<TableLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_dark">
<TextView
android:text="Row 1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light">
<TextView
android:text="Row 2"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_bright">
<TextView
android:text="Row 3"/>
</TableRow>
</TableLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:text="Second column, rowspan 3"
android:background="@android:color/holo_purple"
android:gravity="center"/>
</TableRow>
</TableLayout>
</LinearLayout>
所以,你总结一下:
TableLayout:第一列(TableLayout 与我们想要的尽可能多的 TableRows),第二列(将占用所有这些行空间的元素)。