一、需求场景
今天看到UI设计有一个炫酷的进度条样式,那必须要做出来的效果,如下:
前面的这个LV6就别管了,这是我盖在上面的一个View。
二、需求实现
实现过程,首先我们使用ProgressBar,使用它的水平样式,并自定义progressDrawable(使用layout-list,progressbar有三层:@android:id/background、@android:id/secondaryProgress、@android:id/progress)第一层是进度条的底部背景(对应需求的透明黑背景),第二次是缓存层(对应需求的渐变红),第三层是进度层(对应需求的白色点点)
源码:
xml布局:
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_gravity="center_vertical"
android:progressDrawable="@drawable/task_prograss" />
task_prograss.xml(放在drawable目录下)
<?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="4dip" />
<solid android:color="#3F000000" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<scale android:scaleWidth="100%">
<shape>
<corners android:radius="4dip" />
<gradient
android:angle="0"
android:endColor="#FF9442"
android:startColor="#FF0F00" />
</shape>
</scale>
</item>
<item android:id="@android:id/progress">
<scale
android:drawable="@drawable/icon_progress_drawable"
android:scaleWidth="100%" />
</item>
</layer-list>
点9图:(白色的看不清,注意就在下面哈)
activity代码:
三、总结
要注意的是scale这个属性,以前都没使用过这个,不知道有这东西。还有就是我这里是静态的进度条,只做展示用,有要做动态的可以试试用,应该没问题。(最顶部的效果图就是上面代码实现的)