android - 更改 Android SeekBar 以在主要进度之上绘制次要进度?

标签 android seekbar

我想更改 android seekbar 的行为,以便辅助 android seekbar 实际上绘制在主要 android seekbar 之上。从此处列出的 ProgressBar 文档: http://developer.android.com/reference/android/widget/ProgressBar.html#attr_android:secondaryProgress

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

辅助进度条的当前外观:

Default secondary progress bar

二级进度条的期望外观:

Desired secondary progress bar

理想情况下,我想重写 Android 中 ProgressBar.java 中的一个方法来更改绘制顺序,以便将次要进度条绘制在主要进度条之上,但我很难找到合适的区域在要覆盖的源代码中。有什么想法吗?

我已经成功地尝试使用相对布局在另一个之上绘制两个进度条,但这种方法需要创建两个控件。

最佳答案

这是一个迟到的答案,但我只是找到了如何做到这一点。没那么难:)

首先看看在android项目[这里].( https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/progress_horizontal_holo_dark.xml ) 中如何定义进度drawable

您所要做的就是调换 secondaryProgress 和 progress 的顺序,使 progress 位于 secondaryProgress 之前(位于下方),如下所示:

<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>

现在遗憾的是这些资源不公开。所以你必须复制 progress_bg_holo_dark.9.png , progress_primary_holo_dark.9.pngprogress_secondary_holo_dark.9.png到您的项目 drawable-xhdpi 文件夹(也可能与其他 dpi 图像相同)。

然后像下面这样调整 xml 文件(只需删除“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>

关于android - 更改 Android SeekBar 以在主要进度之上绘制次要进度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20618746/

相关文章:

android - 更新到依赖项 24.2.0 后,在两个布局之间使用 FloatingActionButton 的渲染问题停止工作

java - 禁用时如何使搜索栏变灰?

android - 使 seekbar thumb hitbox 更大

android - Seekbar 背景图片不够大

安卓搜索栏

android - 如何合并数据时间

java - 确定应用程序启动后 30 天 Java

android - 使用 url 启动我的应用程序时如何获取参数?

基本菜单示例中的 XML 问题

java - HH : MM in Range Bar