rajeshlawrance
rajeshlawrance

Reputation: 559

If ScrollView only supports one direct child, How to display the whole layout scrollable?

Here i am showing the xml layout of my application.i want to scroll the whole pages using Scrollview .But i am unable to use.ScrollView only supports one direct child.But i wanna to scroll the whole content.please help me to solve this problem?

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent" android:layout_width="match_parent"
    android:orientation="vertical"
    >


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/prev"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_gravity="left"
                android:background="@null"
                android:src="@drawable/left_white" />

            <EditText
                android:layout_width="185dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="25dp"
                android:hint="" 
                android:visibility="invisible"
                />

            <ImageButton
                android:id="@+id/tour"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="right"
                android:layout_marginLeft="17dp"
                android:background="@null"
                android:src="@drawable/logo" />

            </LinearLayout>
                        <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_gravity="center"
                >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="What interests you?"
        android:textSize="20dp" >

</TextView>
</LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="fill_horizontal"
                android:orientation="horizontal"
                >

                <com.android.example.CoverFlow
                    android:id="@+id/coverFlow"
                    android:layout_width="match_parent"
                    android:layout_height="150dip"/>

            </LinearLayout>
<LinearLayout 
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="17dp"
    >

</LinearLayout>
<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

</LinearLayout>

</LinearLayout>

Upvotes: 1

Views: 1972

Answers (5)

androidcodehunter
androidcodehunter

Reputation: 21947

You cannot use ListView inside ScrollView. Many of us got this problem. So here is the solution of this question:

  1. Create a list.xml that contains just ListView
  2. Create a header.xml that contains above the XML code of ListView
  3. Create a footer.xml that contains below the XML code of ListView

At last, from your main class grab the ListView reference and add list Header and Footer. Hope this will work. If you have any problem with this make sure your comment.

Upvotes: 0

Aerrow
Aerrow

Reputation: 12134

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

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
         android:layout_width="fill_parent"
        android:orientation="vertical" >

    <!-- add your entire layout here -->



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent" android:layout_width="match_parent"
        android:orientation="vertical">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal" >

                <ImageButton
                    android:id="@+id/prev"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_gravity="left"
                    android:background="@null"
                    android:src="@drawable/left_white" />

                <EditText
                    android:layout_width="185dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="25dp"
                    android:hint="" 
                    android:visibility="invisible"
                    />

                <ImageButton
                    android:id="@+id/tour"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_gravity="right"
                    android:layout_marginLeft="17dp"
                    android:background="@null"
                    android:src="@drawable/logo" />

                </LinearLayout>
                            <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_gravity="center"
                    >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="What interests you?"
            android:textSize="20dp" >

    </TextView>
    </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="fill_horizontal"
                    android:orientation="horizontal"
                    >

                    <com.android.example.CoverFlow
                        android:id="@+id/coverFlow"
                        android:layout_width="match_parent"
                        android:layout_height="150dip"/>

                </LinearLayout>
    <LinearLayout 
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="17dp"
        >

    </LinearLayout>
    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#b5b5b5"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector" />

    </LinearLayout>

    </LinearLayout>

    </ScrollView>

Upvotes: 0

Chirag
Chirag

Reputation: 56935

Put Scroll view before your main LinearLayout.

<LinearLayout>
    <ScrollView>
       <LinearLayout>
             // This Linear Layout contains your entire layout code
       </LinearLayout>
    </Scrollview>
   </LinearLayout>

Upvotes: 2

Shrikant Ballal
Shrikant Ballal

Reputation: 7087

Agreed. It supports only one child. But if you want the above xml file to be scrollable, Put your main Linearlayout inside scrollView tag. The main LinearLayout will be considered as single child of ScrollView.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent" android:layout_width="match_parent"
    android:orientation="vertical"
    >
    <LinearLayout 
    android:layout_height="match_parent" android:layout_width="match_parent"
    android:orientation="vertical"
    >
    ...
</ScrollView>

Upvotes: 0

Siddhesh
Siddhesh

Reputation: 1380

you can do this

<your main layout>    
<ScrollView>
<LinearLayout>

 your whole layout code here
</LinearLayout>
</Scrollview>
</your main layout>

Upvotes: 1

Related Questions