做个笔记,主要是需要使用ClipDrawable、LayerDrawable:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
private void setProgressBg( int progress) {
int a = progress * 255 / 100 ;
int color = Color.argb(a, 255 , 90 , 147 );
ColorDrawable colorDrawable = new ColorDrawable();
colorDrawable.setColor(color);
ClipDrawable clipDrawable = new ClipDrawable(colorDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
Drawable drawable = getResources().getDrawable(R.color.transparent);
Drawable[] layers = new Drawable[]{drawable,clipDrawable};
LayerDrawable layerDrawable = new LayerDrawable(layers);
layerDrawable.setDrawableByLayerId( 0 ,drawable);
layerDrawable.setDrawableByLayerId( 1 ,clipDrawable);
progressBar.setProgressDrawable(clipDrawable);
progressBar.setProgress( 0 );
progressBar.setProgress(progress);
Loger.d( "Vote投票" , "result = " + progress);
Loger.d( "Vote投票" , "a = " + a);
}
|
本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1739160,如需转载请自行联系原作者