Android horizontal progress bar?

后端 未结 1 521
忘了有多久
忘了有多久 2020-12-28 19:58

I\'d like to implement a progress bar like this

\"enter

Please help how can I

相关标签:
1条回答
  • 2020-12-28 20:36

    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

    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.

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

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

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

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

    Other progress bar examples:

    Custom progress bar 1

    Custom progress bar 2

    Custom progress bar 3

    UPDATE:

    Also check DiscreteSeekBar this is a great github project.

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

    Cheers,

    0 讨论(0)
提交回复
热议问题