2013-05-08 53 views
0

我想在Android中構建一個簡單的表格佈局,但是我遇到了一些問題。 在第1部分:有一些文本視圖,所以我想將TableRow的高度設置爲wrap_content。 在第2部分:同樣的事情。Android:製作簡單的佈局

它的工作原理都還在,但現在:

在第3部分:有2列表視圖-S,並在第4部分有一些按鈕。

我想這樣做: 讓零件4的高度包裹內容,但使零件3填充屏幕上的所有空白區域。

a busy cat http://i42.tinypic.com/21jye76.png

請給我一個解決方案爲此,東陽當我探測的第3部分填寫所有emty空間,直到屏幕的底部。現在我嘗試了weight_sum,但我不喜歡它,因爲我會讓4'd行換成wrap_content。

<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

tableRow3集合的android:layout_height0,並android:layout_weight1。其他tableRows可以使用android:layout_height="wrap_content"

+0

非常感謝:) – TAR515 2013-05-08 07:55:13

1

創建一個RelativeLayout的父,裏面放上了TableLayouts。這可以讓你使用alignParentBottom和alignParentTop layaout params。

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>