Changing Android SeekBar to draw secondary progress on top of primary progress?

 ̄綄美尐妖づ 提交于 2019-12-02 13:28:36

问题


I would like to change the behavior of an android seekbar so that the secondary android seekbar is actually drawn on top of the primary android seekbar. From the ProgressBar documentation listed here: http://developer.android.com/reference/android/widget/ProgressBar.html#attr_android:secondaryProgress

This progress is drawn between the primary progress and the background.

Current look of secondary Progress bar:

Desired look of secondary progress bar:

Ideally I'd like to override a method in ProgressBar.java in Android to change the order of drawing so that the secondary progress bar is drawn on top of the primary progress bar, but I've had difficulty finding the proper area in the source code to override. Any ideas where to look?

I have had success attempting to draw two progress bars one on top of another using a relative layout, but this approach requires creating two controls.


回答1:


This is a late answer, but just I found out how to do this. Not that difficult :)

First of all look at how the progress drawable is defined in the android project [here].(https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/progress_horizontal_holo_dark.xml)

All you have to do is switch the order of secondaryProgress and progress so that progress comes before (lies below) secondaryProgress like this:

<item android:id="@android:id/background"
      android:drawable="@android:drawable/progress_bg_holo_dark" />

<item android:id="@android:id/progress">
    <scale android:scaleWidth="100%"
           android:drawable="@android:drawable/progress_primary_holo_dark" />
</item>

<item android:id="@android:id/secondaryProgress">
    <scale android:scaleWidth="100%"
           android:drawable="@android:drawable/progress_secondary_holo_dark" />
</item>

Now sadly those resources are not public. So you will have to copy progress_bg_holo_dark.9.png, progress_primary_holo_dark.9.png and progress_secondary_holo_dark.9.png to your projects drawable-xhdpi folder (and maybe to the same with other dpi images as well).

Then adjust the xml file like the following (just remove "android:"):

<item android:id="@android:id/background"
      android:drawable="@drawable/progress_bg_holo_dark" />

<item android:id="@android:id/progress">
    <scale android:scaleWidth="100%"
           android:drawable="@drawable/progress_primary_holo_dark" />
</item>

<item android:id="@android:id/secondaryProgress">
    <scale android:scaleWidth="100%"
           android:drawable="@drawable/progress_secondary_holo_dark" />
</item>



来源:https://stackoverflow.com/questions/20618746/changing-android-seekbar-to-draw-secondary-progress-on-top-of-primary-progress

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!