Reprint please indicate the source of Wang 亟亟 's Daniel Road
Don't say a word more, first.
The state of a circular rotation
Project structure
A sample package, a Lib package. Lib package in fact only a tired, a lot of content in the material files, compare suggestions to copy the content, paste into their own projects
Main class:
Public class mainactivity extends actionbaractivity {Circleprogressview Mcircleview; Switch Mswitchspin; Switch Mswitchshowunit; SeekBar Mseekbar; SeekBar mseekbarspinnerlength;@Override protected void onCreate(Bundle savedinstancestate) {if(Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {webview.setwebcontentsdebuggingenabled (true); }Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Mcircleview = (Circleprogressview) Findviewbyid (R.id.circleview); Mcircleview.setmaxvalue ( -); Mcircleview.setunit ("%"); Mcircleview.setvalue (0);//setup SwitchMswitchspin = (Switch) Findviewbyid (R.ID.SWITCH1); Mswitchspin.setoncheckedchangelistener (NewCompoundbutton.oncheckedchangelistener () {@Override Public void oncheckedchanged(Compoundbutton Buttonview,BooleanisChecked) {if(isChecked) {Mcircleview.spin (); }Else{mcircleview.stopspinning (); } } }); Mswitchshowunit = (Switch) Findviewbyid (R.ID.SWITCH2); Mswitchshowunit.setoncheckedchangelistener (NewCompoundbutton.oncheckedchangelistener () {@Override Public void oncheckedchanged(Compoundbutton Buttonview,BooleanisChecked) {mcircleview.setshowunit (isChecked); } });//setup SeekBarMseekbar = (SeekBar) Findviewbyid (R.id.seekbar); Mseekbar.setmax ( -); Mseekbar.setonseekbarchangelistener (NewSeekbar.onseekbarchangelistener () {@Override Public void onprogresschanged(SeekBar SeekBar,intProgressBooleanFromuser) {}@Override Public void Onstarttrackingtouch(SeekBar SeekBar) { }@Override Public void Onstoptrackingtouch(SeekBar SeekBar) {mcircleview.setvalueanimated (seekbar.getprogress (), the); Mswitchspin.setchecked (false); } }); Mseekbarspinnerlength = (SeekBar) Findviewbyid (R.ID.SEEKBAR2); Mseekbarspinnerlength.setmax ( the); Mseekbarspinnerlength.setonseekbarchangelistener (NewSeekbar.onseekbarchangelistener () {@Override Public void onprogresschanged(SeekBar SeekBar,intProgressBooleanFromuser) {}@Override Public void Onstarttrackingtouch(SeekBar SeekBar) { }@Override Public void Onstoptrackingtouch(SeekBar SeekBar) {Mcircleview.setspinningbarlength (seekbar.getprogress ()); } }); }@Override Public Boolean Oncreateoptionsmenu(Menu menu) {//inflate the menu; This adds items to the action bar if it is present.//Getmenuinflater (). Inflate (R.menu.menu_main, menu); return true; }@Override Public Boolean onoptionsitemselected(MenuItem Item) {//Handle Action Bar item clicks here. The Action Bar would //automatically handle clicks on the Home/up button, so long //As you specify a parent activity in Androidmanifest.xml.//int id = item.getitemid (); //noinspection simplifiableifstatement//if (id = = r.id.action_settings) {//return true;// } return Super. onoptionsitemselected (item); }@Override protected void OnStart() {Super. OnStart (); Mcircleview.setvalue (0); Mcircleview.setvalueanimated (0); }}
Analysis:
A Circleprogressview custom control, 2 Seekbar to control the percentage of the progress bar, as well as the length, 2 switches to toggle the display, and a bunch of displayed TextView
The SetValue () method can be called in OnStart () to assign a value to the progress bar. The internal implementation is also a series of operations that handle the parameters.
/** * Set the value of the circle view without an animation. * Stops any currently active animations. */ publicvoidsetValue(float _value) { new Message(); msg.what = AnimationMsg.SET_VALUE.ordinal(); newfloat[]{_value, _value}; mAnimationHandler.sendMessage(msg); }
The
is called SetValue (msg, Circleview) in the Handlemessage method; The
finally implements the SetValue (Message msg, Circleprogressview _circleview) method
private void setValue(Message msg, CircleProgressView _circleView) { _circleView.mValueFrom = _circleView.mValueTo; _circleView.mCurrentValue = _circleView.mValueTo = ((float[]) msg.obj)[0]; _circleView.mAnimationState = AnimationState.IDLE; _circleView.invalidate(); }
So, in the process of code manipulation, you can call the SetValue () method arbitrarily, regardless of the other parts of the content will have an impact.
The Mseekbarspinnerlength.setmax (360) in the sample code is equal to Mcircleview.setspinningbarlength (Seekbar.getprogress ()); Give the ring Spinningbar a value of int so that he shows a figure with an angle of seekbar.getprogress ()/360. Of course, when you pass in the value of <360, Seekbar pull to the end will not become the whole circle so >360, as long as the arrival of the 360 circle has been rendered, the extra value will have no effect.
Effect
And then we look at the core class Circleprogressview
publicclass CircleProgressView extends View 继承于View
Then voluminous 1300 + lines of code, I do not analyze each, some of the paintings are used, 亟亟 do not do too much explanation, they can see the source, in order to use that we look at some configuration
//Dimension Parameters Private intMlayoutheight =0;Private intMlayoutwidth =0;Private intMfullradius = -;Private intMcircleradius = the;Private intMbarwidth = +;Private intMrimwidth = +;Private intMtextsize = -;Private floatMcontoursize =1;Private floatMtextscale =1;Private floatMunitscale =1;
For the whole size of the graph ah, radius ah, font size AH, etc. to set.
//Color Private Final intMbarcolorstandard =0xff009688;//stylish Blue Private intMcontourcolor =0xaa000000;Private intMspinnercolor = Mbarcolorstandard;//stylish Blue Private intMfillcolor =0x00000000;//transparent Private intMrimcolor =0xaa83d0c9;Private intMtextcolor =0xff000000;Private intMunitcolor =0xff000000;Private int[] Mbarcolors =New int[]{Mbarcolorstandard,//stylish BlueMbarcolorstandard,//stylish Blue};
Color setting, circle color, word color, etc.
privatefloat2.8f; 动画的滚动速度
Generally speaking, it is very convenient to use, attach the source code everyone see it
Http://yunpan.cn/cdLfFUxTaNydr Access Password 6c65
Custom view, another kind of progress bar rendering, Circleprogressview use parsing