Giter Club home page Giter Club logo

verticalseekbar's Introduction

VerticalSeekBar

License Platform API

Android Weekly Download

Presentation

Demo

This is the source code of an Android library: -=:[ VerticalSeekBar ]:=-

๐Ÿ“ƒ Check also the Medium article about it!


Why would you need it?

"Reinventing the wheel is, most of the time, a bad idea."
If you've ever tried to make a vertical SeekBar work properly, you know this is not the case. ๐Ÿ˜
From the moment you apply that android:rotation="270" all start to get messy: you cannot set the proper height for the drawable; the width of the bar distorts the width of your drawable; even customizing your interaction with the bar is kind of tricky.
I've been through all of this and suddenly I've had enough.

Introducing a nicer, redesigned and highly customizable VerticalSeekBar.

What you got:

  • custom progress drawable: apply resources or color gradients
  • custom thumb: chose your size, background color, corner radius or even to completely hide it
  • view width and drawable width completely separated
  • choose how to set your progress (just sliding the thumb, clicking around, or both)
  • min and max placeholders
  • much more!

How to use it?

Make sure to include the library in your app's build.gradle:

    implementation 'com.lukelorusso:verticalseekbar:1.2.0'

Add the view to your layout:

<com.lukelorusso.verticalseekbar.VerticalSeekBar
        android:layout_width="160dp"
        android:layout_height="280dp"/>

maybe add some attributes... here you got some, we'll discuss them later

        ...
        app:vsb_click_to_set_progress="false"
        app:vsb_bar_corner_radius="15dp"
        app:vsb_bar_width="60dp"
        app:vsb_bar_background="#eeeeee"
        app:vsb_bar_progress_gradient_end="#4dd0e1"
        app:vsb_bar_progress_gradient_start="#03a2ba"
        app:vsb_max_placeholder_position="inside"
        app:vsb_max_placeholder_src="@drawable/max_placeholder"
        app:vsb_min_placeholder_position="inside"
        app:vsb_min_placeholder_src="@drawable/min_placeholder"
        app:vsb_progress="50"
        app:vsb_show_thumb="true"
        app:vsb_thumb_container_corner_radius="5dp"
        app:vsb_thumb_container_tint="@color/placeholderBackground"
        app:vsb_thumb_placeholder_src="@drawable/thumb_placeholder"
        app:vsb_use_thumb_to_set_progress="true"
        ...

All of them can be also set programmatically.

(Please note: it's strongly recommended to avoid pre-1.2.0 versions due to inconsistencies compared to this guide)


Attributes

Background and Progress

To set your progress value programmatically:

mainVerticalSeekBar.progress = 75

Do you need a smaller or bigger range? You can change maxValue like this:

mainVerticalSeekBar.maxValue = 70 // "progress" will be automagically reduced!

Let's put some color on this view, shall we?
You can set a drawable for the background and a drawable for the progress. If you don't, default colors will be applied.

For both background and progress you have 3 choices:

  • set a start color and an end color, the view will create a gradient for you
  • set a drawable resource or color (REMEMBER: this choice has priority on the one before)
  • just don't choose (it's still a choice anyway ๐Ÿ˜‰)

Example for the first choice: apply a gradient

mainVerticalSeekBar.barBackgroundStartColor = ContextCompat.getColor(this, R.color.my_background_start_color)
mainVerticalSeekBar.barBackgroundEndColor = ContextCompat.getColor(this, R.color.my_background_end_color)
mainVerticalSeekBar.barProgressStartColor = ContextCompat.getColor(this, R.color.my_progress_start_color)
mainVerticalSeekBar.barProgressEndColor = ContextCompat.getColor(this, R.color.my_progress_end_color)

Example for the second choice: apply a resource (will eventually override the first one)

mainVerticalSeekBar.barBackgroundDrawable = getDrawable(R.color.my_background_color)
mainVerticalSeekBar.barProgressDrawable = getDrawable(R.drawable.my_progress)

Your bar can also have rounded corners...

mainVerticalSeekBar.barCornerRadius = 40 // those are pixels

...and a proper independent width

mainVerticalSeekBar.barWidth = 30 // those are pixels

Placeholders

To set minimum and/or maximum placeholders (null is a possible value to remove them):

mainVerticalSeekBar.minPlaceholderDrawable = getDrawable(R.drawable.my_min_placeholder)
mainVerticalSeekBar.maxPlaceholderDrawable = getDrawable(R.drawable.my_max_placeholder)

Since v1.1.4 you can also choose placeholders' position
You can choose between {"inside", "outside", "middle"} ("middle" by default)
Programmatically, it will be:

mainVerticalSeekBar.minPlaceholderPosition = VerticalSeekBar.Placeholder.INSIDE
mainVerticalSeekBar.maxPlaceholderPosition = VerticalSeekBar.Placeholder.OUTSIDE

Now about the thumb placeholder ๐Ÿ‘†
It is child of a androidx.cardview.widget.CardView. You can choose the color tint and the corner radius of the CardView:

mainVerticalSeekBar.thumbContainerColor = ContextCompat.getColor(this, R.color.my_thumb_background_color)
mainVerticalSeekBar.thumbContainerCornerRadius = 15 // those are pixels

You can set your thumb drawable like this:

mainVerticalSeekBar.thumbPlaceholderDrawable = getDrawable(R.drawable.my_thumb_placeholder)

If you just don't want to see it:

mainVerticalSeekBar.showThumb = false

Interaction

You can interact with your VerticalSeekBar in two ways:

  • sliding the thumb
  • tapping on the bar

Both those interactions can be disabled if you like (they are true by default).
For instance, It can be useful to disable sliding in case you need to put the VerticalSeekBar on a ScrollView.
To do so:

mainVerticalSeekBar.useThumbToSetProgress = false
mainVerticalSeekBar.clickToSetProgress = true

Try to change those booleans too see other possibilities!

Still want more?

If this level of customization is not enough, I have one last good news for you: the seekbar layout is ENTIRELY CUSTOMIZABLE!

You can pick the original layout_verticalseekbar.xml and put it in your project's res/layout folder.

Now you can modify it as you wish; just remember to keep all the original ids! ๐Ÿ˜‰ (thumbCardView and thumbPlaceholder can be safely removed)


Explore!

Feel free to checkout and launch the example app ๐ŸŽก

Also, see where using this library has been the perfect choice:

ColorBlindClick
ColorBlindClick


Copyright

Make with ๐Ÿ’š by Luca Lorusso, licensed under Apache License 2.0
Thanks for the help to Lopez Mikhael

verticalseekbar's People

Contributors

lukelorusso avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.