We need to download the progress of a download, and maybe the product to a beautiful interface, rather than the android comes with the progress bar, in this thank http://blog.csdn.net/lmj623565791/article/details/ 24500107 Blog's selfless dedication
No more nonsense, just cut into the subject.
Create a new Android project first: Customprogressbar
Do you remember the steps to customize the view?
1. Custom View Properties
2. Get our custom properties in the View construction method
[3, rewrite onmesure]
4. Rewrite OnDraw
A: Custom properties under Values/attrs
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<attr name= "Firstcolor" format= "Color"/>
<attr name= "Secondcolor" format= "Color"/>
<attr name= "Circlewidth" format= "Dimension"/>
<attr name= "Speed" format= "integer"/>
<declare-styleable name= "Customprogressbar" >
<attr name= "Firstcolor"/>
<attr name= "Secondcolor"/>
<attr name= "Circlewidth"/>
<attr name= "Speed"/>
</declare-styleable>
</resources>
B: Layout file
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Xmlns:custom= "Http://schemas.android.com/apk/res/com.example.customprogressbar"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
>
<com.example.customprogressbar.customprogressbar
Android:layout_width= "120DP"
android:layout_height= "120DP"
Android:layout_alignparenttop= "true"
android:layout_margintop= "20DP"
Android:layout_centerhorizontal= "true"
Custom:circlewidth= "15DP"
Custom:firstcolor= "#D4F668"
Custom:secondcolor= "#2F9DD2"
Custom:speed= "/>"
<com.example.customprogressbar.customprogressbar
Android:layout_width= "200DP"
android:layout_height= "200DP"
Android:layout_alignparentbottom= "true"
Android:layout_centerhorizontal= "true"
Custom:circlewidth= "24DP"
Android:layout_marginbottom= "40DP"
Custom:firstcolor= "#16A3FA"
Custom:secondcolor= "#D20F02"
Custom:speed= "Ten"/>
</RelativeLayout>
C: Get the custom attribute in the constructor:
TypedArray a = Context.gettheme (). Obtainstyledattributes (Attrs, R.styleable.customprogressbar, Defstyle, 0);
int n = a.getindexcount ();
for (int i = 0; i < n; i++)
{
int attr = A.getindex (i);
Switch (attr)
{
Case R.styleable.customprogressbar_firstcolor:
Mfirstcolor = A.getcolor (attr, Color.green);
Break
Case R.styleable.customprogressbar_secondcolor:
Msecondcolor = A.getcolor (attr, color.red);
Break
Case R.styleable.customprogressbar_circlewidth:
Mcirclewidth = A.getdimensionpixelsize (attr, (int) typedvalue.applydimension (
TYPEDVALUE.COMPLEX_UNIT_PX, Getresources (). Getdisplaymetrics ());
Break
Case R.styleable.customprogressbar_speed:
Mspeed = A.getint (attr, 20);//Default 20
Break
}
}
A.recycle ();
Mpaint = new Paint ();
Keep writing at night.
Android Custom View (ii) ring alternating wait effect