项目作者: hieupham1993

项目描述 :
Standalone scrollbar for Android
高级语言: Kotlin
项目地址: git://github.com/hieupham1993/android-standalone-scroll-bar.git
创建时间: 2020-12-03T08:42:31Z
项目社区:https://github.com/hieupham1993/android-standalone-scroll-bar

开源协议:Apache License 2.0

下载


Demo

Integration

Gradle:

This library is available on jitpack.io.

Step 1. Add the JitPack repository to your build file

Add this in your root build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }
Step 2. Add the dependency

  1. implementation 'com.github.I3eyonder:android-standalone-scroll-bar:x.y.z'

Usage

Xml

  1. <androidx.recyclerview.widget.RecyclerView
  2. android:id="@+id/recyclerView"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent" ></androidx.recyclerview.widget.RecyclerView>
  5. <com.hieupt.android.standalonescrollbar.StandaloneScrollBar
  6. android:id="@+id/scrollbar"
  7. android:layout_width="wrap_content"
  8. android:layout_height="match_parent" ></com.hieupt.android.standalonescrollbar.StandaloneScrollBar>

Code

  1. scrollbar.attachTo(recyclerView)

To using with [NestedScrollView, ScrollView, HorizontalScrollView, WebView], please use [NestedScrollView2, ScrollView2, HorizontalScrollView2, WebView2] for your layout instead.

  1. scrollbar.attachTo(nestedScrollView2)

You can also implement your own ScrollableView to use StandaloneScrollBar with any View. You can refer VerticalScrollViewHelper or HorizontalScrollViewHelper for example of implementation.

  1. scrollbar.attachTo(scrollableView)

Customization

  • Custom track/thumb visibility by using VisibilityManager
    1. scrollbar.visibilityManager = YourCustomVisibilityManager()
  • Custom track/thumb drawable using attribute scrollbarTrackDrawable and scrollbarThumbDrawable or through java/kotlin
    1. scrollbar.customTrackDrawable = customDrawable
    2. scrollbar.customThumbDrawable = customDrawable
  • Tint track/thumb by using attribute scrollbarDefaultTrackTint and scrollbarDefaultThumbTint
    1. scrollbar.defaultThumbTint = ColorStateList()
    2. scrollbar.defaultTrackTint = ColorStateList()
  • Custom thumb length by using attribute scrollbarThumbLength|scrollbarThumbLengthByTrackRatio|scrollbarMinThumbLength|scrollbarAutoThumbLength. If multi attributes is set, the priorities order will be scrollbarThumbLength > scrollbarThumbLengthByTrackRatio > scrollbarAutoThumbLength
    1. scrollbar.thumbLength = desireLengthInPx
    2. scrollbar.thumbLengthByTrackRatio = percentOfTrackLength //[0.0..1.0]
    3. scrollbar.minThumbLength = desireLengthInPx
    4. scrollbar.autoThumbLength = true|false
  • Enable/Disable thumb bar drag ability using attribute scrollbarDraggable
    1. scrollbar.draggable = true|false
  • Auto hide ability (attribute scrollbarAlwaysShow)
    1. scrollbar.isAlwaysShown = true|false
  • Delay duration before scrollbar auto hide (attribute scrollbarDelayBeforeAutoHideDuration)
    1. scrollbar.delayBeforeAutoHide = delayTimeInMillis