Android Custom Horizontal progress bar fillet Progress _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.