The vertical Seekbar:verticalseekbar

Source: Internet
Author: User

This is one of the more useful vertical seekbar codes that I've found: [Java] View plaincopy on code to derive from my Code slice Public classVerticalseekbarextendsAbsseekbar {Privatedrawable Mthumb;  Public InterfaceOnseekbarchangelistener {voidOnprogresschanged (Verticalseekbar Verticalseekbar,intProgressBooleanFromuser); voidOnstarttrackingtouch (Verticalseekbar verticalseekbar); voidOnstoptrackingtouch (Verticalseekbar verticalseekbar); }        PrivateOnseekbarchangelistener Monseekbarchangelistener;  PublicVerticalseekbar (Context context) { This(Context,NULL); }         PublicVerticalseekbar (Context context, AttributeSet attrs) { This(context, Attrs, Android.)      R.attr.seekbarstyle); }         PublicVerticalseekbar (context context, AttributeSet attrs,intDefstyle) {          Super(context, attrs, Defstyle); }         Public voidSetonseekbarchangelistener (Onseekbarchangelistener l) {Monseekbarchangelistener=l; }        voidOnstarttrackingtouch () {if(Monseekbarchangelistener! =NULL) {Monseekbarchangelistener.onstarttrackingtouch ( This); }      }        voidOnstoptrackingtouch () {if(Monseekbarchangelistener! =NULL) {Monseekbarchangelistener.onstoptrackingtouch ( This); }      }        voidOnprogressrefresh (floatScaleBooleanFromuser) {drawable Thumb=Mthumb; if(Thumb! =NULL) {Setthumbpos (GetHeight (), thumb, scale, integer.min_value);          Invalidate (); }          if(Monseekbarchangelistener! =NULL) {monseekbarchangelistener.onprogresschanged ( This, Getprogress (), ispressed ()); }      }        Private voidSetthumbpos (intW, drawable Thumb,floatScaleintGap) {          intAvailable = W-getpaddingleft ()-getpaddingright (); intThumbwidth =thumb.getintrinsicwidth (); intThumbheight =thumb.getintrinsicheight (); Available-=Thumbwidth; //The extra space for the thumb-to-move on the trackAvailable + = Getthumboffset () * 2; intThumbpos = (int) (Scale *available); intTopbound, Bottombound; if(Gap = =integer.min_value) {Rect Oldbounds=thumb.getbounds (); Topbound=Oldbounds.top; Bottombound=Oldbounds.bottom; } Else{Topbound=Gap; Bottombound= Gap +Thumbheight; } thumb.setbounds (Thumbpos, Topbound, Thumbpos+thumbwidth, Bottombound); } @Overrideprotected voidOnDraw (Canvas c) {c.rotate (-90);//invert 90 degrees and put the horizontal seekbar upC.translate (-getheight (), 0);//move the Verticalseekbar after rotation to the correct position, paying attention to the rotation width and height value interchange        Super. OnDraw (c); } @Overrideprotected synchronized voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) {          Super. Onmeasure (Heightmeasurespec, Widthmeasurespec); Setmeasureddimension (Getmeasuredheight (), Getmeasuredwidth ());//wide and high value interchange} @Override Public voidSetthumb (drawable thumb) {Mthumb=thumb; Super. Setthumb (thumb); } @Overrideprotected voidOnsizechanged (intWintHintOLDW,intOLDH) {          Super. onsizechanged (H, W, OLDW, OLDH);//wide and high value interchange    }        //identical to the source code, only the Onstarttrackingtouch () method for calling the wide and high value interchange processing@Override Public Booleanontouchevent (Motionevent event) {if(!isenabled ()) {              return false; }          Switch(Event.getaction ()) { CaseMotionevent.action_down: {setpressed (true);              Onstarttrackingtouch ();              Tracktouchevent (event);  Break; }             Casemotionevent.action_move: {tracktouchevent (event);              Attemptclaimdrag ();  Break; }             Casemotionevent.action_up: {tracktouchevent (event);              Onstoptrackingtouch (); Setpressed (false); //ProgressBar doesn ' t know to repaint the thumb drawable//In it inactive state when the touch stops (because the//value has not apparently changed)invalidate ();  Break; }             Casemotionevent.action_cancel: {Onstoptrackingtouch (); Setpressed (false); Invalidate (); //See above explanation             Break; }            default:               Break; }          return true; }        //wide and high value interchange processing    Private voidtracktouchevent (Motionevent event) {Final intHeight =getheight (); Final intAvailable = Height-getpaddingbottom ()-Getpaddingtop (); intY = (int) event.gety (); floatScale ; floatProgress = 0; if(Y > Height-Getpaddingbottom ()) { Scale= 0.0f; } Else if(Y <Getpaddingtop ()) { Scale= 1.0f; } Else{ Scale= (float) (Height-getpaddingbottom ()-Y)/(float) available; }          Final intMax =Getmax (); Progress= Scale *Max; Setprogress ((int) progress); }        Private voidAttemptclaimdrag () {if(GetParent ()! =NULL) {getParent (). Requestdisallowintercepttouchevent (true); }}} put it up and save it, students who need it can take it directly.-v-2014-04-02Please use the attention of the students, Onprogressrefresh () This method, must ensure that it is not confused. This method, in fact its role is to rewrite the parent class method, but add @override will error, please be careful. 

The vertical Seekbar:verticalseekbar

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.