How do I get the thumb of an Android SeekBar to match the height of the SeekBar?

谁说我不能喝 提交于 2019-12-18 04:25:18

问题


Do I need to implement a custom thumb Drawable?


回答1:


With some digging, I found how to supply a custom Drawable thumb. Here's an excerpt that may help others.

  ShapeDrawable thumb = new ShapeDrawable( new RectShape() );
  thumb.getPaint().setColor( 0x00FF00 );
  thumb.setIntrinsicHeight( 80 );
  thumb.setIntrinsicWidth( 30 );
  mySeekBar.setThumb( thumb );



回答2:


It's an old post, but I found this from google. so here's my solution:

Drawable thumb; //load this earlier.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    thumb = getContext().getResources().getDrawable(R.drawable.slider_thumb);
}

private void expandThumb(int height) {
    thumb.setBounds(0, 0, thumb.getIntrinsicWidth(), height); 
    //force a redraw
    int progress = getProgress();
    setProgress(0);
    setProgress(progress);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    expandThumb(h);
}


来源:https://stackoverflow.com/questions/3648311/how-do-i-get-the-thumb-of-an-android-seekbar-to-match-the-height-of-the-seekbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!