如何类似地在 android 中创建 TableLayout Html Table
How to create TableLayout in android similarly Html Table
我使用 Html
代码创建了 table,如下所示,
现在,如何使用 TableLayout
在 Android 中做到这一点。
Note:
如果需要,我会 post 我的 html
代码。
使用GridLayout
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:rowCount="3"
android:columnCount="3"
android:layout_height="wrap_content">
<Button
android:text="1"
android:background="#00f"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_rowSpan="2"
android:layout_width="wrap_content"/>
<Button
android:text="2"
android:layout_columnSpan="2"
android:layout_gravity="fill"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<Button
android:text="3"
android:layout_gravity="fill"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<Button
android:text="4"
android:layout_rowSpan="2"
android:layout_gravity="fill"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<Button
android:text="5"
android:layout_gravity="fill"
android:layout_columnSpan="2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</GridLayout>
Output
我使用 Html
代码创建了 table,如下所示,
现在,如何使用 TableLayout
在 Android 中做到这一点。
Note:
如果需要,我会 post 我的 html
代码。
使用GridLayout
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:rowCount="3"
android:columnCount="3"
android:layout_height="wrap_content">
<Button
android:text="1"
android:background="#00f"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_rowSpan="2"
android:layout_width="wrap_content"/>
<Button
android:text="2"
android:layout_columnSpan="2"
android:layout_gravity="fill"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<Button
android:text="3"
android:layout_gravity="fill"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<Button
android:text="4"
android:layout_rowSpan="2"
android:layout_gravity="fill"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<Button
android:text="5"
android:layout_gravity="fill"
android:layout_columnSpan="2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</GridLayout>
Output