Peacetime projects often used to customize the progress bar style, we generally achieve the following is the first, as for the second round of the progress of the information on the Internet is not a lot, here together to show the realization of these two.
Let's start looking at the code, starting with the main interface layout:
<progressbar
style= "@android: Style/widget.progressbar.horizontal"
android:layout_width= "Match_ Parent "
android:layout_height=" "20DP"
android:layout_margin= "10DP"
android:max= "MB"
android: Progress= "android:progressdrawable=" and
"@drawable/layer_list_progress_drawable_1"/>
<progressbar
style= "@android: Style/widget.progressbar.horizontal"
android:layout_width= "Match_parent
" android:layout_height= "20DP"
android:layout_margin= "10DP"
android:max= "android:progress="
"
android:progressdrawable=" @drawable/layer_list_progress_drawable "/>
Two progress bar layouts, followed by different progressdrawable layouts:
Layer_list_progress_drawable_1.xml
<?xml version= "1.0" encoding= "Utf-8"?> <layer-list xmlns:android=
"Http://schemas.android.com/apk/res" /android ">
<item
android:id=" @android: Id/background "
android:drawable=" @drawable/shape_ Progressbar_bg "/>
<item android:id=" @android: id/progress ">
<clip android:drawable=" @drawable /shape_progressbar_progress "/>
</item>
</layer-list>
Layer_list_progress_drawable.xml
<?xml version= "1.0" encoding= "Utf-8"?> <layer-list xmlns:android=
"http://schemas.android.com/apk/" Res/android ">
<item
android:id=" @android: Id/background "
android:drawable=" @drawable/shape _progressbar_bg "/>
<item android:id=" @android: id/progress ">
<scale
android:drawable= "@drawable/shape_progressbar_progress"
android:scalewidth= "100%"/>
</item>
</ Layer-list>
From the above two layout files can be seen, layout files are basically the same, the only difference is the item progress attribute value.
Item background can also be set directly in the ProgressBar configuration file,
If you set the layer-list inside, you should also pay attention to the order in which the item is added.
Here is the background, and the progress file:
Shape_progressbar_bg.xml
<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<corners android:radius=" 10DP "/>
<solid android:color=" #e2e2e2 "/>
</ shape>
shape_progressbar_progress.xml
<?xml version= "1.0" encoding= "Utf-8"?>
xmlns : android= "http://schemas.android.com/apk/res/android" >
<corners android:radius= "10DP"/>
< Solid android:color= "#f25252"/>
</shape>
These two are basically the same.
Progress bar fillet Progress is this way, if you do not understand the properties of the configuration file, please Google yourself.
Click to download: Http://xiazai.jb51.net/201608/yuanma/andrioid-progress (jb51.net). rar
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.