自定义进度有ProgressBar.png

progressBar进度条有两个部分组成,背景图形和加载进度图形,使用<layer-list>标签,分别用background和progress作为两个部分的id值,背景图形使用<shape>,加载进度图形还需要用<clip>标签对图形<shape>标签进行包裹。

在res下的drawable文件夹下,创建样式

custom_progress.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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 android:shape="rectangle">
<corners android:radius="5dp"/>
<gradient android:startColor="#fff"
android:endColor="#fff"/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip><!--可裁剪对象-->
<shape android:shape="rectangle">
<corners android:radius="5dp"/>
<gradient android:angle="45"
android:startColor="#f00"
android:endColor="#f90"/>
</shape>
</clip>
</item>
</layer-list>

布局xml,需要指定ProgressBar的style

1
2
3
4
5
6
7
8
9
10
<ProgressBar
android:id="@+id/progressSelf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:progressDrawable="@drawable/custom_progress"/>
<TextView
android:id="@+id/tvProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


Android     

本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!