我想在Android中构建一个简单的表格布局但我遇到了一些问题。 在第1部分:有一些文本视图,所以我想把TableRow的高度放到wrap_content。 在第2部分:同样的事情。
它现在仍然有效但是:
在第3部分:有2个listview-s,第4部分有一些按钮。
我想做这样的事情: 让部分4的高度包裹内容,但让第3部分填满屏幕上的所有空白区域。
a busy cat http://i42.tinypic.com/21jye76.png
请给我一个解决方案,因为当我探测到第3部分填满所有空间直到屏幕底部。现在我尝试使用weight_sum但我不喜欢它,因为我会让4'd行包裹内容。
<TableLayout 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:background="@android:color/black"
android:weightSum="1.0" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:weightSum="1.0" >
<TextView
android:id="@+id/phone_tab_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:background="@layout/style_right_border"
android:gravity="center"
android:singleLine="true"
android:text="Phone Tab"
android:textColor="@android:color/white"
android:textSize="14dp" />
<TextView
android:id="@+id/pc_tab_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="center"
android:singleLine="true"
android:text="PC Tab"
android:textColor="@android:color/white"
android:textSize="14dp" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@layout/style_bottom_border" >
<TextView
android:id="@+id/phone_path_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:background="@layout/style_bott_right_border"
android:gravity="center"
android:paddingBottom="5dp"
android:singleLine="true"
android:text="mnt/sdcard/Movies/dpad/sadas/asda/sda/as"
android:textColor="@android:color/white"
android:textSize="8dp" />
<TextView
android:id="@+id/pc_path_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="center"
android:paddingBottom="5dp"
android:singleLine="true"
android:text="mnt/sdcard/Movies/dpad/sadas/asda/sda/as"
android:textColor="@android:color/white"
android:textSize="8dp" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="0.9"
android:weightSum="1.0" >
<ListView
android:id="@+id/listview_phone_files"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:background="@layout/style_right_border" />
<ListView
android:id="@+id/listview_pc_files"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="0.1"
android:background="@layout/style_top_border"
android:gravity="center"
android:weightSum="1.0" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Button" />
<ImageButton
android:id="@+id/button_active_tab_changer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:background="@android:color/transparent"
android:onClick="changeActiveTabButton"
android:src="@drawable/button_change_tab" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Button" />
</TableRow>
答案 0 :(得分:1)
将RelativeLayout创建为父级,并将TableLayouts放在其中。这允许你使用alignParentBottom和alignParentTop layaout params。
答案 1 :(得分:1)
检查此布局,但请保留旧的布局文件备份。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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:background="@android:color/black"
android:weightSum="1.0" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:weightSum="1.0" >
<TextView
android:id="@+id/phone_tab_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:singleLine="true"
android:text="Phone Tab"
android:textColor="@android:color/white"
android:textSize="14dp" />
<TextView
android:id="@+id/pc_tab_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="center"
android:singleLine="true"
android:text="PC Tab"
android:textColor="@android:color/white"
android:textSize="14dp" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/phone_path_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:paddingBottom="5dp"
android:singleLine="true"
android:text="mnt/sdcard/Movies/dpad/sadas/asda/sda/as"
android:textColor="@android:color/white"
android:textSize="8dp" />
<TextView
android:id="@+id/pc_path_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="center"
android:paddingBottom="5dp"
android:singleLine="true"
android:text="mnt/sdcard/Movies/dpad/sadas/asda/sda/as"
android:textColor="@android:color/white"
android:textSize="8dp" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" >
<ListView
android:id="@+id/listview_phone_files"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<ListView
android:id="@+id/listview_pc_files"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="0.1"
android:gravity="center"
android:weightSum="1.0" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Button" />
<ImageButton
android:id="@+id/button_active_tab_changer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:background="@android:color/transparent"
android:onClick="changeActiveTabButton"
android:src="@android:drawable/ic_delete" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Button" />
</TableRow>
</TableLayout>
答案 2 :(得分:0)
将tableRow3
的{{1}}设置为android:layout_height
,将0
设置为android:layout_weight
。其他1
可以使用tableRows
。