【问题标题】:Is it possible to have two table layout in android UIandroid UI中是否可以有两个表格布局
【发布时间】:2011-12-16 11:14:50
【问题描述】:
我需要在一个 UI 中显示两个不同的表格,我尝试了表格布局,因为通过表格布局很容易拥有表格结构。但我不能在一个屏幕上有两个表格布局。我试图在父布局中添加表格布局视图,例如相对或线性布局,它不起作用。然后我尝试将表格添加为父表格布局中的行,但没有任何效果。它在膨胀视图时没有显示任何错误或警告,但它只显示最后一个表格布局。一个屏幕上不可能有两个表格布局。
【问题讨论】:
标签:
android
android-layout
tablelayout
【解决方案1】:
将两个TableLayouts 包装在LinearLayout 中,并在TableLayouts 上定义android:layout_weight:
<?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>