android中的Custom Listview Fast Scrollbar

Sta*_*ser 12 android

我想定制一个带有可触摸快速滚动条的列表视图,例如谷歌播放音乐应用程序,带有垂直线和拇指图像.它提供了一种简单快捷的方式来滚动这个可触摸的快速滚动条.我试着像这样搜索自定义滚动条,但我在listview中找不到任何快速滚动条.我期待滚动条的输出如下图所示:

在此输入图像描述

外面的快速滚动条用红线标出.我在StackOverflow上发现了这篇文章,但是链接中的代码并没有给我预期的输出.你能帮帮我吗?

Sta*_*ser 37

最后,我想出了一个解决方案.它仅适用于API级别11或更高级别

值/ style.xml

<style name="AppTheme" parent="@style/Theme.Sherlock.Light">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:fastScrollThumbDrawable">@drawable/fast_thumb</item>
        <item name="android:fastScrollTrackDrawable">@drawable/fastscroll_track_default_holo_dark</item>

</style>
Run Code Online (Sandbox Code Playgroud)

应用此主题的活动,如下面的代码:

         <activity
            android:name="com.example.viewpager.FirstActivity"
            android:theme="@style/AppTheme"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
Run Code Online (Sandbox Code Playgroud)

活动布局XML如下代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rlScrollingPlayList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:fastScrollEnabled="true"
            android:fastScrollAlwaysVisible="true"
            android:scrollbarStyle="outsideInset"
            android:layout_height="match_parent" >
        </ListView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

资源图像文件

在此输入图像描述 在此输入图像描述 在这里输入

快速滚动拇指选择器XML文件:

绘制/ fast_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_pressed="true" android:drawable="@drawable/fastscroll_thumb_pressed_holo"/>
    <item android:drawable="@drawable/fastscroll_thumb_default_holo"></item>

</selector>
Run Code Online (Sandbox Code Playgroud)

最终输出如下图:

在此输入图像描述