Search code examples
androidlayoutandroid-tablelayout

Android: making a simple layout


I would like to construct a simple table layout in Android BUT I got some problems with it. At part 1: there are some text views so I would like to put that TableRow's height to wrap_content. At part 2: same thing.

It works all still now BUT:

At part 3: there are 2 listview-s and at part 4 there are some buttons.

I would like to do something like this: let the part 4's height to wrap content but make the part 3 to fill all the empty space on the screen.

a busy cat

Please give me a solution for this, beacause when i probed the part 3 filled out all the emty space till the bottom of the screen. Now I tryed with weight_sum BUT I do not like it because I would let the 4'd row to 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>


Solution

  • set tableRow3's android:layout_height to 0, and android:layout_weight to 1. The other tableRows can use android:layout_height="wrap_content".