Android水平进度条?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22177006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:37:14  来源:igfitidea点击:

Android horizontal progress bar?

androidprogress-bar

提问by youssefhassan

I'd like to implement a progress bar like this

我想实现这样的进度条

enter image description here

在此处输入图片说明

Please help how can I do it or if there is a library

请帮助我怎么做或者如果有图书馆

回答by MSA

I saw that a lot of people are looking on this post so I thought that I should edit it and share an example:

我看到很多人都在看这篇文章,所以我想我应该编辑它并分享一个例子:

Note (this example is not complete, it's still in progress but I guess it's a starting point)

注意(这个例子并不完整,它仍在进行中,但我想这是一个起点)

GitHub: Github Example

GitHub:Github 示例

enter image description here

在此处输入图片说明

The important part in this example is below: Create in drawable a xml file custom_progress_bar_horizontal.xml and add the content below.

这个例子中的重要部分如下: 在 drawable 中创建一个 xml 文件 custom_progress_bar_horizo​​ntal.xml 并添加下面的内容。

<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@android:id/background">
        <shape>
            <padding
                android:bottom="3dip"
                android:top="3dip"
                android:left="3dip"
                android:right="3dip"/>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="#2a2b2f"
                android:centerColor="#2a2b2f"
                android:centerY="0.50"
                android:endColor="#2a2b2f"
                android:angle="270" />
        </shape>
    </item>
    <item
        android:id="@android:id/progress">
        <clip>
            <shape>
                <corners
                    android:radius="5dip" />
                <gradient
                    android:startColor="#ff0e75af"
                    android:endColor="#ff1997e1"
                    android:angle="90" />
            </shape>
        </clip>
    </item>
</layer-list>

Add the following code in styles.xml

在styles.xml中添加以下代码

<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/custom_progress_bar_horizontal</item>
    <item name="android:minHeight">10dip</item>
    <item name="android:maxHeight">20dip</item>
</style>

After you have added the style in your activity layout add:

在活动布局中添加样式后,添加:

    <ProgressBar
        android:id="@+id/customProgress"
        style="@style/CustomProgressBar"
        android:layout_width="match_parent"/>

The progress dispaly below in a frame it's a little tricky because you need to extend the ProgressBar class and make the changes there.

下面的进度显示在一个框架中,这有点棘手,因为您需要扩展 ProgressBar 类并在那里进行更改。

I will leave here some examples and notify when I will add them in my github project.

我将在这里留下一些示例,并通知我何时将它们添加到我的 github 项目中。

Great example if you want to disaply the progress in your way: NumberProgressBar

如果您想以自己的方式显示进度,这是一个很好的例子: NumberProgressBar

Other progress bar examples:

其他进度条示例:

Custom progress bar 1

自定义进度条 1

Custom progress bar 2

自定义进度条 2

Custom progress bar 3

自定义进度条 3

UPDATE:

更新:

Also check DiscreteSeekBarthis is a great github project.

还要检查DiscreteSeekBar这是一个很棒的 github 项目。

Gradle: compile 'org.adw.library:discrete-seekbar:1.0.1'

Gradle:编译'org.adw.library:discrete-seekbar:1.0.1'

Cheers,

干杯,