前言

记录一下SeekBar代码设置setThumb的使用。

正文

xml中Seekbar的配置

  1. <SeekBar
  2. android:id="@+id/seek_bar_1"
  3. android:layout_width="920dp"
  4. android:layout_height="40dp"
  5. android:max="100"
  6. android:progress="100"
  7. android:progressDrawable="@drawable/seek_bar_bg_2"
  8. android:thumb="@drawable/seek_thumb"
  9. android:thumbOffset="0dp" />
复制

PS : 如果不设置 android:thumbOffset=”0dp” ,也就是thmub不从进度0开始,就没问题。

但是如果设置了

  1. android:thumbOffset="0dp"
复制

就可能存在问题。也就是java代码中通过setThumb设置,就存在偏移。

PS:通过setThumb设置这种比较少,比如一般动态换肤需要,或者不重新走Activity生命周期时需要静态的替换。

原因是mThumbOffset被重新赋值了,解决方式就是把mThumbOffset从新设置回去就行。

  1. public void setThumb(Drawable thumb) {
  2. //
  3. if (thumb != null) {
  4. // Assuming the thumb drawable is symmetric, set the thumb offset
  5. // such that the thumb will hang halfway off either edge of the
  6. // progress bar.
  7. mThumbOffset = thumb.getIntrinsicWidth() / 2;
  8. }
  9. //
  10. }
复制

网上有很多方式,这里我只是方便自己自己整理一下,方便自己查阅。

隐藏内容!
付费阅读后才能查看!
2
多个隐藏块只需支付一次

参考文章

无,有点久了忘记了。

相关文章

暂无评论

none
暂无评论...