Android listview not scrolling

Pranav picture Pranav · Sep 5, 2012 · Viewed 15.9k times · Source

i have a layout whose starting tag(parent tag is ) is

<scroll view  
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

later i have many images , textView , Edit text and other things, and finally a list view. i have defined the hight of listview as 230dp as prescribed to me. the thing is the whole layout is scrolling nice, but the content inside the listview is not scrolling individually . this is how the xml looks...

    <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical" >
    <TextView android:layout_width="fill_parent"
         android:layout_height="50dp"
         android:text="BISCOOT"
         android:textSize="25dp"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="200dp" android:background="#ff000000">

      <ImageSwitcher android:id="@+id/switcher1" android:layout_width="fill_parent" 
      android:layout_height="200dp"  
      android:layout_alignParentLeft="true" android:layout_alignParentRight="true" >
      </ImageSwitcher> 
        <ProgressBar
              android:id="@+id/progressBar2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"  android:layout_centerHorizontal="true"
               />
        <ImageButton android:id="@+id/imageButton1" android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" android:src="@android:drawable/ic_media_ff" /> 

        <ImageButton android:id="@+id/imageButton2" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_alignParentLeft="true" 
      android:layout_alignTop="@+id/imageButton1" android:src="@android:drawable/ic_media_rew" /> 
  </RelativeLayout>
    <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Latest headLines"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
         <LinearLayout android:orientation="vertical"
             android:layout_width="fill_parent"            
             android:layout_height="fill_parent">
      <ListView 
        android:id="@android:id/list" 
        android:layout_width="fill_parent" 
        android:scrollbarFadeDuration="0" 
        android:scrollbarStyle="outsideOverlay" 
        android:smoothScrollbar="true" 
          android:layout_height="260dp">
     </ListView>
    </LinearLayout>



    <!-- 
    <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Heroin On the Rocks"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="fill_parent" 
     android:layout_height="200dp" android:background="#ff000000">

      <ImageSwitcher android:id="@+id/switcher2" android:layout_width="fill_parent" 
      android:layout_height="200dp"  
      android:layout_alignParentLeft="true" android:layout_alignParentRight="true" /> 

        <ImageButton android:id="@+id/imageButton3" android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" android:src="@android:drawable/ic_media_ff" /> 

        <ImageButton android:id="@+id/imageButton4" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:layout_alignParentLeft="true" 
      android:layout_alignTop="@+id/imageButton1" android:src="@android:drawable/ic_media_rew" /> 
  </RelativeLayout>
  -->




<TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Watch Movies"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="100dp" android:orientation="horizontal"
    android:weightSum="6"
    >
        <ImageView 

            android:layout_height="100dp"
            android:layout_width="wrap_content" android:layout_weight="1"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg1"
            />
         <ImageView android:layout_height="100dp"
            android:layout_width="wrap_content" android:layout_weight="1"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg2"/>
          <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg3"/>

          <ProgressBar
              android:id="@+id/progressBar3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center" />

           <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg4"/>
            <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg5"/>
             <ImageView android:layout_height="100dp" android:layout_weight="1"
            android:layout_width="wrap_content"
           android:layout_marginLeft="2dp" android:layout_marginRight="2dp"
            android:id="@+id/watchmoviesimg6"/>


    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="200dp" 
    android:orientation="vertical"
    >
              <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Photo Stories"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>

              <ProgressBar
                  android:id="@+id/progressBar4"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center" />

               <ImageView 
                   android:id="@+id/photostoryimageview1"
                   android:layout_height="200dp" android:layout_weight="1"
            android:layout_width="fill_parent"
            />
               </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="200dp" 
    android:orientation="vertical"
    >
                 <TextView android:layout_width="fill_parent"
         android:layout_height="30dp"
         android:text="Star Special"
         android:background="@drawable/item_bg_light"
         android:textColor="@android:color/white"
         android:gravity="center"/>

                 <ProgressBar
                     android:id="@+id/progressBar5"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content" 
                     android:layout_gravity="center"/>

               <ImageView 
                   android:id="@+id/starSpecialimageView1"
                   android:layout_height="200dp" android:layout_weight="1"
            android:layout_width="fill_parent"
            />
               </LinearLayout>

</LinearLayout>
</ScrollView>

Answer

Praveenkumar picture Praveenkumar · Sep 5, 2012

Simply, remove the ScrollView from your layout. And, make the LinearLayout as parent. And, try to run your app. It will scroll the list.

Because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView I strongly recommend you to simplify your layout somehow. For example you can add views you want to be scrolled to the ListView as headers or footers.

Have a look at this

Update

Take one parent layout with two child. And, in one layout it should contain ScrollView with your contents. And, on another layout contain your ListView Try like this He has done like that one.