问题
I need to show two different tables in one UI, i tried for table layout cause it is easy to have table structures through table layout. But i could not have two table layout in one screen. I tried to add the table layout views in a parent layout,e.g Relative or Linear layout, it did not work. Then i tried to add the tables as row in a parent table layout, But nothing is working. It did not show any error or warning while inflating the view, but it just show last table layout only. Is it not possible to have two table layout in one screen.
回答1:
Wrap the two TableLayouts
in a LinearLayout
and define android:layout_weight
on the TableLayouts
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ff0000" >
</TableLayout>
<TableLayout
android:id="@+id/tableLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00ff00" >
</TableLayout>
来源:https://stackoverflow.com/questions/7915624/is-it-possible-to-have-two-table-layout-in-android-ui