The Upright Seekbar

Source: Internet
Author: User

The video Player page Volume Control Seekbar achieves a vertical effect. Vertical just will be Seekbar 90 degrees or 90 degrees, we can turn the canvas to an angle, and then to the system to draw, the concrete way is to rewrite the ondraw() adjustment canvas, and then call super.onDraw() .

Up the Seekbar

protected void OnDraw (Canvas c) {    c.rotate (-90);    C.translate (-height,0); // height is the height    of your Verticalseekbar Super . OnDraw (c);}

The downward seekbar should be:

protected void OnDraw (Canvas c) {    c.rotate (+);    C.translate (0,-width); // width is the width    of your Verticalseekbar Super . OnDraw (c);}

Sample code

 Public classVerticalseekbarextendsSeekBar { PublicVerticalseekbar (Context context) {Super(context); }     PublicVerticalseekbar (context context, AttributeSet attrs,intDefstyle) {        Super(context, attrs, Defstyle); }     PublicVerticalseekbar (Context context, AttributeSet attrs) {Super(context, attrs); }    protected voidOnsizechanged (intWintHintOLDW,intOLDH) {        Super. Onsizechanged (H, W, OLDH, OLDW); } @Overrideprotected synchronized voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) {        Super. Onmeasure (Heightmeasurespec, Widthmeasurespec);    Setmeasureddimension (Getmeasuredheight (), Getmeasuredwidth ()); }        protected voidOnDraw (Canvas c) {c.rotate (-90); C.translate (-getheight (), 0); Super. OnDraw (c); } @Override Public synchronized voidSetprogress (intprogress) {            Super. Setprogress (progress); Onsizechanged (GetWidth (), GetHeight (),0, 0); } @Override Public Booleanontouchevent (Motionevent event) {if(!isenabled ()) {                return false; }            Switch(Event.getaction ()) { CaseMotionevent.action_down: CaseMotionevent.action_move: CaseMotionEvent.ACTION_UP:setProgress ((int) ((int) Getmax ()-(Getmax () * event.gety ()/getheight ())));  Break; default:                    return Super. Ontouchevent (event); }            return true; }    }  

The Upright Seekbar

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.