Dan F
Dan F

Reputation: 17732

Linear layout above a scrollview

I've got a simple android layout consisting of a scrollview containing a tablelayout. This table displays properly, but I would like to add a static header above the scrollview, so that basically the labels for the columns in the table remain at the top of the screen always. However, when I add a <LinearLayout> above the <ScrollView> in my layout file, it makes it all disappear.

Can anyone spot what I've done wrong with my xml file?

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="top" >

        <LinearLayout 
            android:id="@+id/header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <TableLayout 
                android:id="@+id/mainTable"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
        </ScrollView>

    </LinearLayout>

As it is, I do not see the scrollview or table layout, but if I remove the header linearlayout, it displays just fine.

Upvotes: 2

Views: 2138

Answers (3)

Adinia
Adinia

Reputation: 3731

LinearLayouts need to have the android:orientation parameter set.

Upvotes: 3

Dimitris Makris
Dimitris Makris

Reputation: 5183

You have to set the orientation of the parent LinearLayout to vertical! By default is set to horizontal that's way you don't see the ScrollView.

and you can try this:

<LinearLayout 
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_weight="0"
        />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="0dp" android:layout_weight="1">

        <TableLayout 
            android:id="@+id/mainTable"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </ScrollView>

Hope this helps!!

Upvotes: 1

josephus
josephus

Reputation: 8304

Your scrollview's layout_height is set to fill_parent. Use wrap_content.

Upvotes: 0

Related Questions