【问题标题】:How to create Custom Horizontal progress bar如何创建自定义水平进度条
【发布时间】:2013-11-30 23:09:02
【问题描述】:

请帮助创建像这样的水平进度条

【问题讨论】:

标签: android progress-bar


【解决方案1】:

设置水平进度条的样式

        style="?android:attr/progressBarStyleHorizontal"

创建自定义进度drawable:green_progress_drawable.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>
        <corners android:radius="5dip" />
        <gradient
            android:startColor="#779d9e9d"
            android:centerColor="#995a5d5a"
            android:centerY="0.75"
            android:endColor="#ff747674"
            android:angle="270"
            />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                android:startColor="#80ffd300"
                android:centerColor="#80ffb600"
                android:centerY="0.75"
                android:endColor="#a0ffcb00"
                android:angle="270"
                />
        </shape>
    </clip>
</item>
<item
    android:id="@android:id/progress"
    >
    <clip>
        <shape>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="#33FF33"
                android:endColor="#008000"
                android:angle="270" />
        </shape>
    </clip>
</item>
</layer-list>

我的进度条代码:

 <ProgressBar
        android:progressDrawable="@drawable/green_progress_drawable"
        style="?android:attr/progressBarStyleHorizontal"

        android:id="@+id/mf_progress_bar"
        app:layout_widthPercent="80%"
        app:layout_heightPercent="8%"
        app:layout_marginTopPercent="5%"
        android:layout_gravity="center_horizontal"
        />

代码归功于@Ryan https://stackoverflow.com/a/5745923/3879847

我的输出:

我希望这篇文章可能对某人有所帮助..

【讨论】:

  • 您忘记关闭 green_progress_drawable.xml 中的 layer-list 标签
【解决方案2】:

您不需要自定义进度条。在布局 xml 文件中使用 style="@android:style/Widget.ProgressBar.Horizontal"。您还需要使用 ProgressBar.incrementProgressBy(int progress);

Android Developers|ProgressBar

【讨论】:

猜你喜欢
  • 2012-06-26
  • 2012-11-04
  • 2019-03-11
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多