今天学习给ProgressBar换个样式,先看效果图:
. n9 u9 |" a2 \/ i# Z
原理:在XML文件中分别定义进度条背景、第一进度颜色、第二进度颜色,然后在ProgressBar的android:progressDrawable属性应用即可。
先在drawable下建立progressbar_style.xml文件,内容如下: 分别定义背景,第一进度颜色,第二进度颜色 % T* t$ e0 b8 P
gradient是渐变,前面已经说过,corners定义的是圆角
* /values/styles.xml . |( C& F0 O$ U
" U& a. s- i( m; r7 C
好了,到此,我们的原料就都备齐了,下面在一个布局文件中测试一下: 3 y$ Q- C m, y6 L$ E
看起来很丑的原因:
1.没有圆角
2.没有透明度
. n9 u9 |" a2 \/ i# Z
原理:在XML文件中分别定义进度条背景、第一进度颜色、第二进度颜色,然后在ProgressBar的android:progressDrawable属性应用即可。
先在drawable下建立progressbar_style.xml文件,内容如下: 分别定义背景,第一进度颜色,第二进度颜色 % T* t$ e0 b8 P
gradient是渐变,前面已经说过,corners定义的是圆角
布局中:
- <ProgressBar android:id="@+id/progressBar1" android:layout_width="fill_parent" android:layout_height="wrap_content"* m7 n& r- K u! c: y# _9 }
- style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/progressbar_style"
- android:progress="50" android:max="100" android:secondaryProgress="70"
- ></ProgressBar>
首先,了解 android 进度条的接口:
1.一个进度条背景 background (奶白色) 9 L; {# Y6 u2 R) p# T: R$ B$ F
2.一个进度条的一级进度显示 progress (绿色)
3.一个进度条的二级进度显示 second progress (红色) (这种情况较少使用)
% x/ w. ?, O: ~; O0 `8 ]
效果如下图:
1.一个进度条背景 background (奶白色) 9 L; {# Y6 u2 R) p# T: R$ B$ F
2.一个进度条的一级进度显示 progress (绿色)
3.一个进度条的二级进度显示 second progress (红色) (这种情况较少使用)
% x/ w. ?, O: ~; O0 `8 ]
效果如下图:
本文将以上三种重要的参数都实现自定义UI。
============================================================== 0 _! J. J$ W w3 \
开始罗,像做菜一样,我们的原料有以下: 8 y0 I* j% i% K3 g8 Q* M
* 9.png 共3张,分别是: 4 P$ O4 q- ~5 e( z* j
进度条背景 my_progress_bg.9.png; 4 K2 [* Q: o# t- F1 v) I* p
一级进度条 my_first_progress.9.png; 7 O+ I- K2 O7 n/ m0 J+ M
二级进度条 my_second_progress.9.png
============================================================== 0 _! J. J$ W w3 \
开始罗,像做菜一样,我们的原料有以下: 8 y0 I* j% i% K3 g8 Q* M
* 9.png 共3张,分别是: 4 P$ O4 q- ~5 e( z* j
进度条背景 my_progress_bg.9.png; 4 K2 [* Q: o# t- F1 v) I* p
一级进度条 my_first_progress.9.png; 7 O+ I- K2 O7 n/ m0 J+ M
二级进度条 my_second_progress.9.png
* /drawable/my_progress.xml 配置文件
* /values/styles.xml . |( C& F0 O$ U
" U& a. s- i( m; r7 C
好了,到此,我们的原料就都备齐了,下面在一个布局文件中测试一下: 3 y$ Q- C m, y6 L$ E
看起来很丑的原因:
1.没有圆角
2.没有透明度
转自:http://www.lephone.net/thread-4186-1-1.html