繁体   English   中英

如何获得Android SeekBar的拇指以匹配SeekBar的高度?

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

我是否需要实现自定义缩略图Drawable?

通过一些挖掘,我找到了如何提供自定义Drawable拇指的方法。 这是一个可以帮助他人的摘录。

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

这是一篇旧文章,但我是从Google找到的。 所以这是我的解决方案:

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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