Created
January 13, 2019 01:48
-
-
Save ar-android/6fc8dd2ae89b8dbaf4db8732c27bf41a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.ahmadrosid.image_slider_android | |
| import android.content.Context | |
| import android.support.v4.view.ViewPager | |
| import android.util.AttributeSet | |
| import android.view.animation.DecelerateInterpolator | |
| import android.widget.Scroller | |
| class SliderView @JvmOverloads constructor( | |
| context: Context, attrs: AttributeSet? = null | |
| ) : ViewPager(context, attrs){ | |
| val DEFAULT_SCROLL_DURATION = 200 | |
| val SLIDE_MODE_SCROLL_DURATION = 1000 | |
| init { | |
| setDurationScroll(DEFAULT_SCROLL_DURATION) | |
| setOnTouchListener { _, _-> true } | |
| } | |
| fun setDurationScroll(millis: Int) { | |
| try { | |
| val viewpager = ViewPager::class.java | |
| val scroller = viewpager.getDeclaredField("mScroller") | |
| scroller.isAccessible = true | |
| scroller.set(this, OwnScroller(context, millis)) | |
| } catch (e: Exception) { | |
| e.printStackTrace() | |
| } | |
| } | |
| inner class OwnScroller(context: Context, durationScroll: Int) : Scroller(context, DecelerateInterpolator()) { | |
| private var durationScrollMillis = 1 | |
| init { | |
| this.durationScrollMillis = durationScroll | |
| } | |
| override fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int, duration: Int) { | |
| super.startScroll(startX, startY, dx, dy, durationScrollMillis) | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment