First, see the effect
Second, on the code
Package com.framework.widget;
Import android.app.Activity;
Import Android.content.Context;
Import Android.content.res.TypedArray;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import Android.graphics.Rect;
Import Android.graphics.RectF;
Import Android.util.AttributeSet;
Import Android.util.DisplayMetrics;
Import Android.view.View; Import com.
R /** * @author Dahai * @ClassName: (imitation Alipay) Proceeds progress bar * @Description: ${todo} * @date ${date} ${time} * @email 202491024@qq. COM * @since $android progress bar */public class Profitprogerssbar extends View {//Background color private static final int Default_bac
K_color = Color.parsecolor ("#ffffff");
The color of the word private static final int default_text_color = Color.parsecolor ("#ffffff");
Progress bar background color private static final int default_progress_color = Color.parsecolor ("#abacaf");
progress bar Default height private static final float default_progress_height =120f;
Text size private static final float default_text_size = 50; /** * Income progress barLeft and right sides MARGIN size * * private static final int margin_size = 20;
private context;
/** * Background color of the brush * * Private Paint backgroundpaint;
/** * Profit Progress color of the brush/private Paint progresspaint;
/** * Draw the text of the brush * * Private Paint textpaint;
/** * Background Width */private int view_background_width;
/** * Background Height * * Private float view_background_height = default_progress_height;
/** * Date/private String date = "2016/12/07";
/** * Description (Percent/yuan)/private String desc = "2.1234";
/** * The percentage of length to display * * Private int progress = 70;
progress bar Color private int progress_color = Default_progress_color;
Background color private int progress_back_color = Default_back_color;
The color of the word is private int text_color = Default_text_color;
The size of the word private float text_size = default_text_size;
Public Profitprogerssbar {Super (context);
Initview (context);
Public Profitprogerssbar (context, AttributeSet attrs) {Super (context, attrs);
Initview (context); } public ProfitprogErssbar (context, AttributeSet attrs, int defstyleattr) {Super (context, attrs, defstyleattr);
Initview (context);
private void Initview {This.context = context;
TypedArray TypedArray = this.context.obtainStyledAttributes (R.styleable.profitprogerssbar); Progress_back_color = Typedarray.getcolor (R.styleable.profitprogerssbar_progress_backg_color,default_back_color)
;
Text_color = Typedarray.getcolor (R.styleable.profitprogerssbar_progress_text_color,default_text_color);
Text_size = Typedarray.getdimension (r.styleable.profitprogerssbar_progress_text_size,default_text_size);
Backgroundpaint = new Paint ();
Backgroundpaint.setstrokewidth (10);
Backgroundpaint.setcolor (Progress_back_color);
Backgroundpaint.setdither (TRUE);
Backgroundpaint.setantialias (TRUE);
Progresspaint = new Paint ();
Progresspaint.setstrokewidth (10);
Progresspaint.setdither (TRUE);
Progresspaint.setantialias (TRUE);
Textpaint = new Paint (); Textpaint.setstrokewidtH (10);
Textpaint.setdither (TRUE);
Textpaint.setantialias (TRUE);
Textpaint.settextsize (text_size);
Displaymetrics d = new Displaymetrics ();
(activity). Getwindowmanager (). Getdefaultdisplay (). Getmetrics (d);
View_background_width = D.widthpixels; /** * Initialization progress bar * @param date * @param desc * @param progress * @param progresscolor/public void init (STR
ing date,string desc,int progress,int progresscolor) {this.date = date;
THIS.DESC = desc;
This.progress = progress;
This.progress_color = Progresscolor;
} @Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas);
View_background_height = This.getmeasuredheight ();
RECTF r = new RECTF ();
R.left = 0;
r.top = 0;
R.right = View_background_width;
R.bottom = view_background_height;////------------------------canvas.drawrect (R, Backgroundpaint);
RECTF r1 = new RECTF ();
R1.left = 0;
r1.top = 0;
R1.right = View_background_width * PROGRESS/100; R1.bottom = View_background_height;////------------------------Progresspaint.setcolor (Progress_color);
Canvas.drawrect (R1, Progresspaint);
Textpaint.setcolor (Text_color);
Rect r2 = new Rect ();
Textpaint.gettextbounds (Date,0,date.length (), R2);
Canvas.drawtext (date, margin_size, (view_background_height-r2.top)/2, textpaint);//Date Rect r3 = new Rect ();
Textpaint.gettextbounds (Desc,0,desc.length (), R3); if (progress>95&&progress<100) {canvas.drawtext (desc, R1.right-textpaint.measuretext (DESC)-MARGIN_
SIZE-30, (View_background_height-r3.top)/2, textpaint); }else if (progress>=100) {canvas.drawtext (desc, R1.right-textpaint.measuretext (DESC)-margin_size-45, (view_
Background_height-r3.top)/2, textpaint); }else {canvas.drawtext (desc, R1.right-textpaint.measuretext (DESC)-Margin_size, (view_background_height-r3.top)/
2, Textpaint);
} invalidate (); }
}
Three
<com.framework.widget.profitprogerssbar
android:layout_width= "match_parent"
android:layout_height= " 35DP "
android:layout_marginleft=" 10DP "
android:layout_marginright=" 10DP "
android:layout_margintop= "10DP"
app:progress_back_color= "@color/white"
app:progress_text_color= "@color/white"
app:progress _text_size= "14DP"
android:id= "@+id/profitprogerssbar"
/>
<declare-styleable name= " Profitprogerssbar ">
<attr name=" progress_backg_color format= "color"/> <attr name=
"Progress _text_color "format=" color "/>
<attr name=" progress_text_size "format=" Dimension "/>
</ Declare-styleable>
The above is a small set to introduce the Android imitation payment treasure in the balance Treasure proceeds progress bar, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!