Skip to content

Instantly share code, notes, and snippets.

@Guiorgy
Last active February 20, 2020 20:01
Show Gist options
  • Select an option

  • Save Guiorgy/be82502f7b839026421014ba8838e7c1 to your computer and use it in GitHub Desktop.

Select an option

Save Guiorgy/be82502f7b839026421014ba8838e7c1 to your computer and use it in GitHub Desktop.
An Android SeekBar, that's flipped horizontally
class ReverseSeekBar : SeekBar {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
init()
}
private var first = true
override fun onTouchEvent(event: MotionEvent): Boolean {
event.setLocation(this.width - event.x, event.y)
return super.onTouchEvent(event)
}
override fun getProgress(): Int {
return max - super.getProgress() + min
}
override fun setProgress(progress: Int) {
super.setProgress(max - progress + min)
}
override fun onDraw(canvas: Canvas?) {
if (first) {
first = false
val old = progress
progress = min + max - progress
super.onDraw(canvas)
progress = old
} else
super.onDraw(canvas)
}
private fun init() {
rotation = 180f
}
}
/*
<ReverseSeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:min="-50"
android:max="50"
android:progress="50"/>
*/
@Guiorgy
Copy link
Copy Markdown
Author

Guiorgy commented Feb 20, 2020

Screenshot_1582215047

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment