First:
We need to customize the progressbar style.
<Span style = "white-space: pre"> </span> <style name = "self_define_progressbar" parent = "@ Android: style/widget. progressbar. horizontal "> // inherits the android horizontal progressbar style <item name =" Android: indeterminateonly "> false </item> <item name =" Android: progressdrawable "> @ drawable/self_define_progress </item> </style>
<? XML version = "1.0" encoding = "UTF-8"?> <Layer-list xmlns: Android = "http://schemas.android.com/apk/res/android"> <item Android: Id = "@ Android: ID/background"> // defines the background color <shape> <corners Android: radius = "5dip"/> <gradient Android: angle = "270" Android: centercolor = "# efefef" Android: centery = "0.75" Android: endcolor = "# a3a3a3" Android: startcolor = "# c7c7c7"/> </shape> </item> <item Android: Id = "@ Android: ID/secondaryprogress "> // if there are two levels of progress, you need to define this item. Gradient defines gradient, and clip does not, the progress bar is filled with the whole progpolicar <clip> <shape> <corners Android: radius = "5dip"/> <gradient Android: angle = "270" Android: centercolor = "#99cc99" Android: centery = "0.75" Android: endcolor = "#99cc99" Android: startcolor = "#99cc99"/> </shape> </clip> </item> <item Android: Id = "@ Android: ID/progress "> // This defines the level 1 progress. If the level 1 Progress is greater than level 2 and the Level 1 progress is not transparent, you can overwrite the 2-level progress <clip> <shape> <corners Android: radius = "5dip"/> <gradient Android: angle = "270" Android: centercolor = "#4 abbfd" Android: centery = "0.75" Android: endcolor = "#4 abbfd" Android: startcolor = "#4 abbfd"/> </shape> </clip> </item> </layer-List>
Use this in the Code:
private ProgressBar mProgressBar;private Task mTask = new Task();private int mCount = 0;private Handler mHander = new MyHandler();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);mProgressBar = (ProgressBar)findViewById(R.id.progress);Timer timer = new Timer();timer.schedule(mTask, 1000, 1000);}private class MyHandler extends Handler{@Overridepublic void handleMessage(Message msg) {mCount += 10;mProgressBar.setProgress(mCount);super.handleMessage(msg);}}private class Task extends TimerTask{@Overridepublic void run() {mHander.sendEmptyMessage(10);}}
Progress bar for a circle with a circle Animation: Value of shape (rectagle rectangle, oval, line horizontal line, ring) value of tpye: gradient style liner linear gradient Radial Ring gradient sweep
<? XML version = "1.0" encoding = "UTF-8"?> <Rotate xmlns: Android = "http://schemas.android.com/apk/res/android" Android: fromdegrees = "0" Android: fromdegrees = "0" Android: todegrees = "360"> <shape Android: Shape = "ring" <span style = "font-family: verdana, MS song,, Arial,, Helvetica, sans-serif; color: #666666; "> <span style =" font-size: 14px; line-Height: 18px; "> </span> Android: innerradiusratio = "3" Android: thicknessratio = "8" Android: uselevel = "false"> <size Android: width = "37dip" Android: height = "37dip"/> <gradient Android: TYPE = "sweep" // if the type is sweep, the Android: uselevel = "false" Android: startcolor = "# f7f7f7" Android: centercolor = "# f7f7f7" Android: centery = "0.50" Android: endcolor = "# b3b4b4"/> </shape> </rotate>