I'm using a drawable for seekbar thumb with
android:thumb="@drawable/thumb"
How can i set the size of this thumb in dip unit? Because i use a style for seekbar like
<style name="CustomSeekBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:minHeight">8dip</item>
<item name="android:maxHeight">8dip</item>
<item name="android:thumbOffset">8dip</item>
</style>
and i want to have the thumb with 12dip
height and width.
Create a shape of rectangle with height and width as you require. Use this shape as drawable for your thumb.
Another simple solution that worked for me was using
scaleX
andscaleY
. The entire seekbar will be larger this way and not just the thumb.From the sdk you can see this is the style for the basic SeekBar:
With this as the thumb selector:
You should be able to use these as a base to replace the drawable which are currently being used (This looks like the stage you've got to).
These drawable can be different sizes on different screens based on drawable folder size bucket (
drawable-hdpi
,drawable-large-hdpi
etc) or you can make differentSeekBar
s look at different styles / drawable sizes like so:I was also looking for a way to do something similar and after looking at some other questions and putting all the answers together, I came up with a way to resize the Seekbar thumb in onCreate().
Here's my code from
onCreate()
, slightly adapted to your needs.Note that this works for resizing your thumb, but it might be clipped because it's bigger than the containing seekbar (not sure about that). If it does get clipped, you might need to create a taller seekbar and create your own seekbar background matching the size you want for the display.
Hope this helps!
I work like this:
just a sample,in your real usage,you should define the width,height and picture of your thumb in a xml file.
The most flexible way to set thumb size for me is to create layered-drawable with shape as placeholder
thumb_image.xml
:So basically changing the size of shape will stretch drawable, the shape is transparent so it won't be visible. Also the minimum size of such thumb is size of bitmap.
Here is example of layout: