我有以下代码:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android: {code is required here}="2">
<TableRow>
<TextView
android:id="@+id/accelerometer_label"
android: {code is required here}="1"
android:text="Accelerometer"
android:textSize="9pt"
android:padding="3dip" />
</TableRow>
我正在尝试将数据显示在三列中,任何想法代码需要在{code is here here}部分中找到?
答案 0 :(得分:7)
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:shrinkColumns="*"
android:stretchColumns="*">
<!-- Row 1 with single column -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:background="#b0b0b0"
android:padding="18dip"
android:text="@string/row_1"
android:textColor="#000"
android:textSize="18sp" />
</TableRow>
<!-- Row 2 with 3 columns -->
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:background="#dcdcdc"
android:gravity="center"
android:padding="20dip"
android:text="@string/row_2_column_1"
android:textColor="#000000" />
<TextView
android:layout_weight="1"
android:background="#d3d3d3"
android:gravity="center"
android:padding="20dip"
android:text="@string/row_2_column_2"
android:textColor="#000000" />
<TextView
android:layout_weight="1"
android:background="#cac9c9"
android:gravity="center"
android:padding="20dip"
android:text="@string/row_2_column_3"
android:textColor="#000000" />
</TableRow>
<!-- Row 3 with 2 columns -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:layout_weight="1"
android:background="#b0b0b0"
android:gravity="center"
android:padding="18dip"
android:text="@string/row_3_column_1"
android:textColor="#000000" />
<TextView
android:layout_weight="1"
android:background="#a09f9f"
android:gravity="center"
android:padding="18dip"
android:text="@string/row_3_column_2"
android:textColor="#000000" />
</TableRow>
</TableLayout>