Seekbar progress drawable异常行为onPause

Seekbar progress drawable abnormal behavior onPause

我在片段中显示搜索栏。搜索栏具有自定义缩略图和进度可绘制对象。它们显示正常,但是当我暂停 activity 和 return 时,进度条宽度奇怪地增加到与拇指相同的高度!我找不到这个异常行为的问题。

如何正常显示

activity 暂停后

我的代码:

// 内部片段 onStart

seekBar.setThumb(getResources().getDrawable(R.drawable.form_bg));
            seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress));

// seekBar xml

<SeekBar
                    android:id="@+id/seekBar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:indeterminate="false"
                    android:layout_marginTop="5dp"
                    android:max="100"
                    android:maxHeight="6dp"
                    android:progress="50" />

// 拇指可绘制

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <size android:height="@dimen/seekbar_tumb_size" android:width="@dimen/seekbar_tumb_size" />
    <solid android:color="@color/form_color" />
</shape>

// 可绘制进度

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:top="0dp" android:bottom="0dp" android:gravity="center_vertical"  android:id="@android:id/background">
    <shape>

        <solid android:color="@color/activity_bg" />
    </shape>
</item>

<item android:gravity="center_vertical" android:id="@android:id/progress">
    <clip>
        <shape>
            <solid android:color="@color/form_color_syrup" />
        </shape>
    </clip>
</item>

终于找到了解决办法。

Rect bounds = seekBar.getProgressDrawable().getBounds();

    seekBar.setThumb(getResources().getDrawable(R.drawable.form_bg));
    seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress));

seekBar.getProgressDrawable().setBounds(bounds);