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
- <ProgressBar
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- Android: indeterminateDrawable = "@ drawable/progress_my_style"
- Style = "? Android: attr/progressBarStyle"
- />
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
- <Animated-rotate xmlns: android = "http://schemas.android.com/apk/res/android"
- Android: drawable = "@ drawable/spinner_color"
- Android: Required Tx = "50%"
- Android: Ty = "50%"
- />
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
- MProgressBar. setIndeterminateDrawable (AppConfig. getResources (). getDrawable (R. drawable. style_common_processbar ));
Style_common_processbar.xml still needs to be defined in xml
[Html]View plaincopy
- <? Xml version = "1.0" encoding = "UTF-8"?>
- <Animated-rotate
- Android: drawable = "@ drawable/icon"
- Android: Required Tx = "50.0%"
- Android: Ty = "50.0%"
- Xmlns: android = "http://schemas.android.com/apk/res/android">
- </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
- // Custom Mode
- MProgressBar. setIndeterminateDrawable (AppConfig. getResources (). getDrawable (R. drawable. style_common_processbar ));
Style_common_processbar.xml
[Html]View plaincopy
- <? Xml version = "1.0" encoding = "UTF-8"?>
- <Rotate
- Xmlns: android = "http://schemas.android.com/apk/res/android"
- Android: duration = "30"
- Android: fromDegrees = "0.0"
- Android: toDegrees = "360.0"
- Android: Required Tx = "50.0%"
- Android: Ty = "50.0%"
- Android: repeatCount = "infinite">
- <Shape
- Android: shape = "ring"
- Android: innerRadiusRatio = "3.2"
- Android: thicknessRatio = "5.333"
- Android: useLevel = "false">
- <Size
- Android: height = "16.0dip"
- Android: width = "16w.dip"/>
- <Gradient
- Android: startColor = "#4 cffffff"
- Android: endColor = "# ffff0000"
- Android: useLevel = "false"
- Android: type = "sweep"
- Android: centery= "0.5"
- Android: centerColor = "#4 cffffff"/>
- </Shape>
- </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
- <? 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/bg"/>
- <Item android: id = "@ android: id/secondaryProgress" android: drawable = "@ drawable/secondary"/>
- <Item android: id = "@ android: id/progress" android: drawable = "@ drawable/progress"/>
- </Layer-list>