gpt4 book ai didi

android - android中的自定义Listview快速滚动条

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:31:45 25 4
gpt4 key购买 nike

我想自定义一个带有可触摸快速滚动条的 ListView ,例如带有竖线和缩略图的 Google Play 音乐应用。它提供了一种简单快捷的方式来滚动这个可触摸的快速滚动条。我尝试搜索这样的自定义滚动条,但在 ListView 中找不到任何具有快速滚动条的内容。我期待滚动条的输出如下图所示:

enter image description here

外面的快速滚动条用红线标出。我找到了 this post在 StackOverflow 上,但链接中的代码没有给我预期的输出。你能帮我做这个吗?

最佳答案

最后,我想出了一个解决办法。它仅适用于API 级别 11 或更高级别

values/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>

像下面的代码一样为这个主题应用 Activity :

         <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>

Activity 布局 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>

资源图片文件

enter image description here enter image description here enter here

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

drawable/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>

最终输出如下图:

enter image description here

关于android - android中的自定义Listview快速滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17337182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com