【问题标题】:How do I get the thumb of an Android SeekBar to match the height of the SeekBar?如何让 Android SeekBar 的拇指与 SeekBar 的高度相匹配?
【发布时间】:2016-05-07 21:47:24
【问题描述】:

我需要实现自定义拇指 Drawable 吗?

【问题讨论】:

    标签: android height scrollbar


    【解决方案1】:

    经过一番挖掘,我发现了如何提供自定义 Drawable 拇指。这是一段可能对其他人有所帮助的摘录。

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

    【讨论】:

      【解决方案2】:

      这是一篇旧帖子,但我是从 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);
      }
      

      【讨论】:

        猜你喜欢
        • 2013-01-03
        • 1970-01-01
        • 1970-01-01
        • 2015-05-11
        • 1970-01-01
        • 2015-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多