1

我的任务是为列表视图创建自定义滚动条,据我所知,您可以自定义滚动条的方式在 android 上非常有限。是否有可能达到这样的完全相同的结果: 在此处输入图像描述

如果是这样,你能给我举一个很好的例子吗,或者至少告诉我应该研究什么?

[编辑] 同样在滚动时,我希望能够使用拇指图标。

4

4 回答 4

4

在drawable中创建这两个xml文件

scrollbar_vertical_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <gradient
        android:angle="0"
        android:endColor="#FF6600"
        android:startColor="#FF6600" />

    <corners android:radius="4dp"/>


</shape>

scrollbar_vertical_track.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >    
    <gradient
        android:angle="0"
        android:endColor="#FFFFFF"
        android:startColor="#FFFFFF" /> 
    <corners android:radius="4dp" />    
</shape>

在 list_view.xml 中使用这两个 xml 文件

list_view.xml

<ListView android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="1dp"
    android:divider="#FF6600"
    android:listSelector="@drawable/list_selector"
    android:layoutAnimation="@anim/listview_layout_animation"
    android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
    android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
    android:scrollbarSize="3dip"
    android:fastScrollEnabled="true">
于 2014-01-10T16:12:40.970 回答
4

在活动级别,您可以指定各种属性来指定滚动条。对于给定的滚动条,您可能必须指定scrollbarThumbVertical,scrollbarTrackVertical属性。可定制属性列表在R.attr中指定。

于 2012-11-05T04:59:15.010 回答
3

在 res/styles.xml 中创建一个主题:

<style name="CustomTheme" parent="android:Theme">
    <item name="android:scrollbarTrackVertical">@drawable/scroll_track</item>
    <item name="android:scrollbarThumbVertical">@drawable/scroll_thumb</item>
</style>

@drawable/scroll_track并且@drawable/scroll_thumb必须引用九个补丁图像或一个形状drawable。滚动轨迹图像是滚动条的背景。滚动拇指负责滚动句柄。然后只需将主题应用于整个应用程序或 AndroidManifest.xml 中的活动:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme">

你可以像我解释的那样做这个,也可以根据你的需要把图片放在drawable中。

于 2012-11-05T05:37:30.037 回答
1

我刚刚在 ListView 旁边使用了单独的 Seekbar。

于 2012-11-08T12:13:46.993 回答