[英]Seekbar progress drawable abnormal behavior onPause
I'm displaying a seekbar inside a fragment. 我正在片段中显示搜索栏。 The seekbar has custom thumb and progress drawables.
搜寻栏具有自定义的缩略图和进度可绘制对象。 They display fine, however when I pause the activity and return to it, the progress bar width strangely increases to the same height of the thumb !
它们显示正常,但是当我暂停活动并返回时,进度条的宽度奇怪地增加到了拇指的相同高度! I can't find the problem for this abnormal behavior.
我找不到这种异常行为的问题。
how it displays normally 它如何正常显示
my code : 我的代码:
// inside fragment onStart //内部片段onStart
seekBar.setThumb(getResources().getDrawable(R.drawable.form_bg));
seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress));
// seekBar xml // 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" />
// thumb drawable //拇指可绘制
<?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>
// progress drawable //可绘制进度
<?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>
Finally found the solution to this. 终于找到了解决办法。
Rect bounds = seekBar.getProgressDrawable().getBounds();
seekBar.setThumb(getResources().getDrawable(R.drawable.form_bg));
seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress));
seekBar.getProgressDrawable().setBounds(bounds);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.