views:

1097

answers:

2

I have a hard time understanding the layout tutorial. I am not able to align columns on different rows. For example, what does 3dip mean in android:padding="3dip". The documentation says "Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters). ".

Specifically, I want to create a layout with top and bottom two rows, and the middle are lists. And I want the bottom row to stick to the bottom. e.g.,


title1 | title 2| title 3|

list 1

list 2

bottom 1 | bottom 2 |

My current xml looks very ugly (without the middle lists)

<?xml version="1.0" encoding="utf-8"?>

<TableRow>
    <TextView
         android:layout_width="wrap_content"
          android:gravity="center_horizontal"
        android:text="title 1"
         />
    <TextView
    android:layout_width="wrap_content"
     android:gravity="center_horizontal"
        android:text="title 2"

         />
        <TextView
         android:layout_width="wrap_content"
          android:gravity="center_horizontal"
        android:text="title 3"            
        />
</TableRow>
<View        android:layout_height="2dip"        
android:background="#FF909090" />
   <TableRow>
    <TextView
         android:layout_width="wrap_content"
          android:gravity="center_horizontal"
        android:text="bottom 1"
         />

        <TextView
         android:layout_width="wrap_content"
          android:gravity="center_horizontal"
        android:text="bottom 2"            
        />
</TableRow>

+3  A: 

A TableLayout isn't really what you need for this. A TableLayout gives you something like Excel, where you have rows and columns.

Also, dip is the same as dp.

Possible Solution:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_height="wrap_content"
        android:id="@+id/TopRow"
        android:layout_width="fill_parent"
        android:orientation="horizontal">

        <TextView
            android:text="@+id/TextView01"
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1" />
        <TextView
            android:text="@+id/TextView01"
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1" />
        <TextView
            android:text="@+id/TextView01"
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1" />

    </LinearLayout>
    <LinearLayout
        android:id="@+id/Middle"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <ListView
            android:id="@+id/ListView01"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:layout_height="fill_parent" />
        <ListView
            android:id="@+id/ListView02"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_weight="1" />

    </LinearLayout>
    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="horizontal"
        android:id="@+id/BottomRow">

        <TextView
            android:text="@+id/TextView01"
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1" />
        <TextView
            android:text="@+id/TextView01"
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="1" />

    </LinearLayout>
</LinearLayout>
CaseyB
Then should I switch to LinearLayout? How to I make the bottom row stick to the very bottom of the screen?
Yang
I updated my answer to show a possible solution.
CaseyB
+1  A: 

A RelativeLayout allows you to tell views to stick to the bottom or top, with the attributes layout_alignParentBottom="true" or layout_alignParentTop="true". See common layouts for more information on the RelativeLayout.

Mayra