Autohide scrollbars when not scrolling in a ListView

前端 未结 4 418
广开言路
广开言路 2021-01-12 09:01

In the new official Twitter app, the scrollbars in all the ListViews the app uses are hidden unless the user is scrolling through the list.

When you start scrollin

相关标签:
4条回答
  • 2021-01-12 09:15

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

    0 讨论(0)
  • 2021-01-12 09:16

    I followed Alex's answer and it worked using both the theme settings and through code.

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

    I did encounter a problem however with the Gallery Component. Whilst the following will compile fine, it will throw a NullPointerException. I assume this is to do with a Gallery not having scrollbars to show/hide.

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

    Android 2.2

    0 讨论(0)
  • 2021-01-12 09:18

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

    0 讨论(0)
  • 2021-01-12 09:30

    You can enable scroll bar fading for your entire app on API level 5 and newer via a custom theme and the 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 set the 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 be sure you're not overriding this global theme on individual activities. Earlier Android versions will safely ignore this unknown XML attribute and not fade the scrollbars.

    0 讨论(0)
提交回复
热议问题