http://liuzhichao.com/p/636.html
进度条默认是不确定(indeterminate=true)Android进度条
Android进度条有4种风格可以使用。
默认值是progressBarStyle。
设置成progressBarStyleSmall后,图标变小。
设置成progressBarStyleLarge后,图标变大
设置成progressBarStyleHorizontal后,变成横向长方形。
自定义圆形进度条ProgressBar的一般有三种方式:
一、通过动画实现
定义res/anim/loading_anim.xml如下:
1
|
<? xml version = "1.0" encoding = "utf-8" ?>
|
2
|
< animation-list android:oneshot = "false"
|
4
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f0" />
|
5
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f1" />
|
6
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f2" />
|
7
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f3" />
|
8
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f4" />
|
9
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f5" />
|
10
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f6" />
|
11
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f7" />
|
12
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f8" />
|
13
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f9" />
|
14
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f10" />
|
15
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f11" />
|
16
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f12" />
|
17
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f13" />
|
18
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f14" />
|
19
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f15" />
|
20
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f16" />
|
21
|
< item android:duration = "150" android:drawable = "@drawable/loading_blue_16_f17" />
|
在layout文件中引用如下:
2
|
android:id = "@+id/progressBar1"
|
3
|
android:layout_width = "wrap_content"
|
4
|
android:layout_height = "wrap_content"
|
5
|
android:layout_gravity = "center_horizontal"
|
6
|
android:layout_marginBottom = "20dip"
|
7
|
android:layout_marginTop = "20dip"
|
8
|
android:indeterminate = "false"
|
9
|
android:indeterminateDrawable = "@anim/loading_anim" />
|
二、通过自定义颜色实现
定义res/drawable/loading_color.xml如下:
1
|
<? xml version = "1.0" encoding = "utf-8" ?>
|
3
|
android:fromDegrees = "0"
|
6
|
android:toDegrees = "360" >
|
8
|
android:innerRadiusRatio = "3"
|
10
|
android:thicknessRatio = "8"
|
11
|
android:useLevel = "false" >
|
13
|
android:centerColor = "#FFDC35"
|
14
|
android:centerY = "0.50"
|
15
|
android:endColor = "#CE0000"
|
16
|
android:startColor = "#FFFFFF"
|
18
|
android:useLevel = "false" />
|
在layout文件中引用如下:
2
|
android:id = "@+id/progressBar2"
|
3
|
android:layout_width = "wrap_content"
|
4
|
android:layout_height = "wrap_content"
|
5
|
android:indeterminate = "false"
|
6
|
android:indeterminateDrawable = "@drawable/loading_color" />
|
三、使用一张图片进行自定义
定义res/drawable/loading_img.xml如下:
1
|
<? xml version = "1.0" encoding = "utf-8" ?>
|
5
|
android:drawable = "@drawable/exchange_loading"
|
6
|
android:fromDegrees = "0.0"
|
9
|
android:toDegrees = "360.0" />
|
在layout文件中引用如下:
2
|
android:id = "@+id/progressBar3"
|
3
|
android:layout_width = "wrap_content"
|
4
|
android:layout_height = "wrap_content"
|
5
|
android:indeterminate = "false"
|
6
|
android:indeterminateDrawable = "@drawable/lodaing_img"
|
时间: 2024-12-10 19:02:15