简体   繁体   中英

how to set attributes to android's seekbar thumb only?

I have build a custom seekbar for my android app.

however I have difficulties tweeking the handle\\thumb size and position

as I think the attrubutes refer to the whole control and I didn't see xml attributes refering to the thumb itself.

Is there any xml way to set the thumb (1)position (2)size and (3) padding?

I have thought maybe doing it via code, but I'm not sure how and I think this is less preferable

pseoudo code like:

Drawable image = getResources().getDrawable(
                          R.drawable.pressed_state).setHight(20dp);

//how to set right padding?

            myZoomBar.setThumb(image );

The thumb drawable used in the SeekBar class is Not a stretchable 9Patch. It is a straight forward png.
If you want a re-sizable thumb, either:

  • Just create a series of thumb images at different sizes and swap them as needed.

or

  • Go to town in your custom SeekBar, overriding onMeasure(), onLayout(), onDraw() and so on, to get it to handle 9Patch resizing (You'll obviously also have to provide your own methods such as setScaleableThumbHeight() and setScaleableThumbWidth()).

Note: "Padding" sets the internal spacing used for any content of a view. Padding in the Thumb Drawable doesn't actually make sense unless you are trying to display something inside the Thumb. The padding of the SeekBar defines the spacing around the outside of the Thumb and Track.

As you would know, you can: - Use the android:progress attribute inherited from ProgressBar to set progress (thumb position) - Use the attributes inherited from View to adjust padding and size of the SeekBar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM