Custom scrollbar for listview

前端 未结 4 1991
南方客
南方客 2021-01-16 04:01

I have a task to create a custom scrollbar for list view and to my knowledge the way you can customize your scrollbar is very limited on android. Is it possible to achieve e

相关标签:
4条回答
  • 2021-01-16 04:44

    Create a theme in 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 and @drawable/scroll_thumb must refer either to nine patch images or to a shape drawables. Scroll track image is a background for the scroll bar. Scroll thumb is responsible for the scroll handle. Then just apply the theme either to whole application or to an activity within AndroidManifest.xml:

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

    you can make this like i explaind and also put the pic in drawable as u want.

    0 讨论(0)
  • 2021-01-16 04:49

    At the activity level, you could specify various attributes to specify the scrollbars. For the given scrollbar, you might have to specify scrollbarThumbVertical, scrollbarTrackVertical attributes. The list of customizable attributes are specified in R.attr.

    0 讨论(0)
  • 2021-01-16 04:50

    Create these two xml file in drawable

    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>
    

    Use these two xml file in list_view.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">
    
    0 讨论(0)
  • 2021-01-16 04:51

    I just ended up using separate Seekbar next to ListView.

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