0

Why is there a Scroll Bar in List View even when the data in displayed in it doesn't require scrolling? here is my xml file

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

   <ListView
      android:id="@+id/listview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:divider="@null"
      android:dividerHeight="0dip" />

   <TextView
      android:id="@+id/empty"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center"
      android:text="@string/no_result_text"
      android:visibility="gone" />

</LinearLayout>
Ketan Ahir
  • 6,678
  • 1
  • 23
  • 45
msd
  • 73
  • 1
  • 7

4 Answers4

0

Comparing getLastVisiblePosition() with getCount() in a Runnable, you will get to know whether your list view will fit into the screen or not. Also check if the last visible row fits entirely on the screen or not.

ListView listView;
Runnable fitsOnScreen = new Runnable() {
    @Override
    public void run() {
        int last = listView.getLastVisiblePosition();
        if(last == listView.getCount() - 1 && listView.getChildAt(last).getBottom() <= listView.getHeight()) {
           listView.setScrollContainer(false);
        }
        else {
            listView.setScrollContainer(true);
        }
    }
};

Finally in ListView's Handler: onCreate()

listView.post(fitsOnScreen);
Umang Mehta
  • 1,467
  • 11
  • 16
0

You can do this by

listView.setScrollContainer(false);

for more please check

How to get a non scrollable ListView?

Community
  • 1
  • 1
Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
0

If you are not want to hide the scrollbar for ever. Then it will help you. Due to android:layout_height="match_parent" on listView and TextView scrollbar appears.

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

     <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" // change 1
        android:divider="@null"
        android:dividerHeight="0dip" />

     <TextView
        android:id="@+id/empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" //change 2
        android:gravity="center"
        android:text="@string/no_result_text"
        android:visibility="gone" />

 </LinearLayout>
Ketan Ahir
  • 6,678
  • 1
  • 23
  • 45
Pradip
  • 3,189
  • 3
  • 22
  • 27
0

android:scrollbars="none"

Try putting the above line in your listview in xml.

Vedang Jadhav
  • 510
  • 2
  • 11