Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making android listview layout scrollable

I have an xml file that has the layout in ASCII form:

---------------
| ImageView
--------------
| TextView
--------------
| List...
--------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.some.app"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<ImageView 
android:id="@+id/MovieCover"
android:layout_width="100dip"
android:layout_height="100dip"
/> 
 <TextView
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textSize="16sp"
    android:padding="10dp"
    android:id="@+id/TextHeader"
    android:background="#000000">
</TextView>
<ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
 android:layout_width="fill_parent">
 </ListView>
 </LinearLayout>

I'm having a problem displaying the layout when my ImageView and TextView takes up more than 3/4 of the screen. How do I make ImageView and TextView scrollable with the ListView that is being displayed? At this point of time, only the ListView to be scrolled and I want the entire layout to be scrollable as though they are one page on its own.

How can I do that?

like image 430
David C Avatar asked Nov 30 '10 05:11

David C


3 Answers

You can use <ScrollView> as your layout container

something along the line of

<ScrollView>
    <LinearLayout>
    // your layout here
    </LinearLayout>
</ScrollView>

the reason why we need the LinearLayout inside is that ScrollView can only have one direct child

like image 78
Andreas Wong Avatar answered Sep 21 '22 20:09

Andreas Wong


Butter to use two LinearLayout with layoutweight="1" and put ScrollView in one and listview in other

<LinearLayout android:layout_weight="1"
        android:layout_height="fill_parent" android:layout_width="fill_parent">
        <ScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"            
                                android:layout_height="fill_parent">

                          <!-- scroll view content -->
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
    <LinearLayout android:layout_weight="1"
        android:layout_height="fill_parent" android:layout_width="fill_parent">
        <ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
            android:layout_width="fill_parent">
        </ListView>
    </LinearLayout>
like image 43
Labeeb Panampullan Avatar answered Sep 20 '22 20:09

Labeeb Panampullan


ListView has addtoHeader and addtoFooter function. Make a separate layout and add it into header of ListView . In your case make a relative layout of imageview and textview and add it to the header of listview. The entire page will start scrolling.

like image 34
Arun Avatar answered Sep 20 '22 20:09

Arun