前言
同样的代码,在不同设备上可能存在不同的表现。目前测试在MTK的平台上发现,使用如下代码:
- <SeekBar
- android:id="@+id/play_sb_process"
- android:layout_width="754dp"
- android:layout_height="40dp"
- android:duplicateParentState="true"
- android:progressDrawable="@drawable/seek_bar_img"
- android:thumb="@color/transparent" />
- <?xml version="1.0" encoding="utf-8"?>
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@android:id/background"
- android:drawable="@drawable/seek_bar_bg_n"/>
- <item
- android:id="@android:id/secondaryProgress"
- android:drawable="@drawable/seek_bar_bg_n"/>
- <item
- android:id="@android:id/progress"
- android:drawable="@drawable/seek_bar_bg_p"/>
- </layer-list>
正文
一开始以为是UI的切图问题,然后找了其他正常的UI放上去,还是存在。
分析
先分析前,需要看一下setThumb源码(初始化也是获取thumb并通过这个方法设置的)。
- public void setThumb(Drawable thumb) {
- final boolean needUpdate;
- if (mThumb != null && thumb != mThumb) {
- mThumb.setCallback(null);
- needUpdate = true;
- } else {
- needUpdate = false;
- }
-
- if (thumb != null) {
- thumb.setCallback(this);
- if (canResolveLayoutDirection()) {
- thumb.setLayoutDirection(getLayoutDirection());
- }
- mThumbOffset = thumb.getIntrinsicWidth() / 2;
- if (needUpdate &&
- (thumb.getIntrinsicWidth() != mThumb.getIntrinsicWidth()
- || thumb.getIntrinsicHeight() != mThumb.getIntrinsicHeight())) {
- requestLayout();
- }
- }
-
- mThumb = thumb;
-
- applyThumbTint();
- invalidate();
-
- if (needUpdate) {
- updateThumbAndTrackPos(getWidth(), getHeight());
- if (thumb != null && thumb.isStateful()) {
- int[] state = getDrawableState();
- thumb.setState(state);
- }
- }
- }
参考文章
© 版权声明