Autohide scroll bars when not scrolling in ListView

In the new official Twitter app, the scroll bars in all the ListViews that the app uses are hidden unless the user scrolls the list.

When you start scrolling, scroll bars appear. When you stop, they disappear with animation until they are gone completely.

I cannot find anything in the documentation that indicates that this is a standard feature.

Is this something included in the API? If not, does anyone know how to do this?

+7
android
source share
4 answers

Confirmed: use orroid: fadeScrollbars (if you are API level 5) or try using setOnScrollListener to check the scroll status and hide / show bars. Some code examples are in this thread: how to detect that Android ListView Scrolling is stopped?

+4
source share

You can enable scrollbar attenuation for the entire application at API level 5 and newer using a custom theme and fadeScrollbars style attribute by adding this to styles.xml :

  <style name="Theme.App" parent="android:Theme.Light"> <item name="android:fadeScrollbars">true</item> </style> 

Then install a new theme for your application in AndroidManifest.xml :

 <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:description="@string/description" android:theme="@style/Theme.App"> 

Just make sure that you do not redefine this global theme into separate actions. Previously, Android versions will safely ignore this unknown XML attribute and not preempt scrollbars.

+4
source share

I haven't used them yet, but you can play with android:scrollbarDefaultDelayBeforeFade and android:scrollbarFadeDuration , available for all widgets (i.e. subclasses of View ).

+1
source share

I followed Alex, and he worked both with the theme settings and with the help of the code.

 GridView gridview = (GridView) findViewById(R.id.mygridView); gridview.setScrollbarFadingEnabled(false); 

However, I had a problem with the Gallery component. While the following will compile in order, it will throw a NullPointerException. I assume this is due to the fact that there are no scroll bars in the gallery to show / hide.

 Gallery gallery = (Gallery) findViewById(R.id.myGallery); gallery.setScrollbarFadingEnabled(false); // <-- this will throw an exception 

Android 2.2

0
source share

All Articles