Android ProgressBar custom mode, custom mode animation file, androidprogressbar

Source: Internet
Author: User

Android ProgressBar custom mode, custom mode animation file, androidprogressbar
1. indeterminate mode | no progress bar for specific progress

1.1 Custom Animation files
[Html]View plaincopy
  1. <ProgressBar
  2. Android: layout_width = "wrap_content"
  3. Android: layout_height = "wrap_content"
  4. Android: indeterminateDrawable = "@ drawable/progress_my_style"
  5. Style = "? Android: attr/progressBarStyle"
  6. />


Note: style = "? Android: attr/progressBarStyle "this is the default style and can be changed

Step 2: Create the progress_my_style.xml file in the drawable Folder: The content can be as follows:

[Html]View plaincopy
  1. <Animated-rotate xmlns: android = "http://schemas.android.com/apk/res/android"
  2. Android: drawable = "@ drawable/spinner_color"
  3. Android: Required Tx = "50%"
  4. Android: Ty = "50%"
  5. />



Note:
1. android: drawable = "@ drawable/spinner_color" here, you should create a spinner_color.png image under drawable( draw your own effect (gradient ))

2. For details about the progress_my_style.xml file, see D: \ andrirod \ android-sdk-windows \ platforms \ android-7 \ data \ res \ drawable \ progress_medium_white.xml, Android: framesCountAnd Android: frameDuratiionIs the internal attribute of frameworks and cannot be directly used, so it is omitted)
The above is directly defined in XML. below is what I directly defined in the Code:
[Java]View plaincopy
  1. MProgressBar. setIndeterminateDrawable (AppConfig. getResources (). getDrawable (R. drawable. style_common_processbar ));


Style_common_processbar.xml still needs to be defined in xml
[Html]View plaincopy
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <Animated-rotate
  3. Android: drawable = "@ drawable/icon"
  4. Android: Required Tx = "50.0%"
  5. Android: Ty = "50.0%"
  6. Xmlns: android = "http://schemas.android.com/apk/res/android">
  7. </Animated-rotate>

The result is that the progress is displayed by rotating the image icon. For details about how to create an image, refer to the image spinner_black_48.png in drawable_hdpi of android.

1.2 custom colors and shapes
Use shape to customize colors and shapes
[Java]View plaincopy
  1. // Custom Mode
  2. MProgressBar. setIndeterminateDrawable (AppConfig. getResources (). getDrawable (R. drawable. style_common_processbar ));

Style_common_processbar.xml
[Html]View plaincopy
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <Rotate
  3. Xmlns: android = "http://schemas.android.com/apk/res/android"
  4. Android: duration = "30"
  5. Android: fromDegrees = "0.0"
  6. Android: toDegrees = "360.0"
  7. Android: Required Tx = "50.0%"
  8. Android: Ty = "50.0%"
  9. Android: repeatCount = "infinite">
  10. <Shape
  11. Android: shape = "ring"
  12. Android: innerRadiusRatio = "3.2"
  13. Android: thicknessRatio = "5.333"
  14. Android: useLevel = "false">
  15. <Size
  16. Android: height = "16.0dip"
  17. Android: width = "16w.dip"/>
  18. <Gradient
  19. Android: startColor = "#4 cffffff"
  20. Android: endColor = "# ffff0000"
  21. Android: useLevel = "false"
  22. Android: type = "sweep"
  23. Android: centery= "0.5"
  24. Android: centerColor = "#4 cffffff"/>
  25. </Shape>
  26. </Rotate>

By modifying
Android: shape = ["rectangle" | "oval" | "line" | "ring"] to modify the shape
Gradient to modify color attributes

2. progress mode | progress bar with percentage progress
Code call: MProgressBar. setProgressDrawable (AppConfig. getResources (). getDrawable (R. drawable. color ));
Color. xml [Html]View plaincopy
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <Layer-list xmlns: android = "http://schemas.android.com/apk/res/android">
  3. <Item android: id = "@ android: id/background" android: drawable = "@ drawable/bg"/>
  4. <Item android: id = "@ android: id/secondaryProgress" android: drawable = "@ drawable/secondary"/>
  5. <Item android: id = "@ android: id/progress" android: drawable = "@ drawable/progress"/>
  6. </Layer-list>

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.