Android Custom slide-up panel

Source: Internet
Author: User

1, inherit Horizontalscrollview, mainly use its characteristics Scrollto and Smoothscrollto method of horizontal scrolling
2, the Almighty Ontouchevent

 Public classSlidingmenuextendshorizontalscrollview{/*** Screen width*/    Private intMscreenwidth; /*** DP*/    Private intmmenurightpadding; /*** Width of menu*/    Private intMmenuwidth; Private intMhalfmenuwidth; Private BooleanIsOpen; Private Booleanonce;  PublicSlidingmenu (Context context, AttributeSet attrs) { This(context, Attrs, 0); }     PublicSlidingmenu (context context, AttributeSet attrs,intDefstyle) {        Super(context, attrs, Defstyle); Mscreenwidth=screenutils.getscreenwidth (context); TypedArray a=context.gettheme (). Obtainstyledattributes (Attrs, R.styleable.slidingmenu, Defstyle,0); intn =A.getindexcount ();  for(inti = 0; I < n; i++)        {            intattr =A.getindex (i); Switch(attr) { Caser.styleable.slidingmenu_rightpadding://defaultMmenurightpadding =a.getdimensionpixelsize (attr, (int) typedvalue.applydimension (Typedvalue.complex_unit_dip, 50f, Getresources (). Getdisplaymetrics ( ));//default is 10DP                 Break;    }} a.recycle (); }     PublicSlidingmenu (Context context) { This(Context,NULL, 0); } @Overrideprotected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) {        /*** Display the setting of a width*/        if(!once) {LinearLayout wrapper= (linearlayout) getchildat (0); ViewGroup Menu= (viewgroup) wrapper.getchildat (0); ViewGroup content= (ViewGroup) wrapper.getchildat (1); Mmenuwidth= Mscreenwidth-mmenurightpadding; Mhalfmenuwidth= MMENUWIDTH/2; Menu.getlayoutparams (). Width=Mmenuwidth; Content.getlayoutparams (). Width=Mscreenwidth; }        Super. Onmeasure (Widthmeasurespec, Heightmeasurespec); } @Overrideprotected voidOnLayout (BooleanChangedintLintTintRintb) {Super. OnLayout (Changed, L, T, R, b); if(changed) {//Hide the menu             This. ScrollTo (mmenuwidth, 0); Once=true; }} @Override Public Booleanontouchevent (motionevent ev) {intAction =ev.getaction (); Switch(action) {//Up , if the display area is greater than half the width of the menu, it is completely displayed, otherwise hidden         Casemotionevent.action_up:intSCROLLX =Getscrollx (); if(Scrollx >mhalfmenuwidth) {                 This. Smoothscrollto (mmenuwidth, 0); IsOpen=false; } Else            {                 This. Smoothscrollto (0, 0); IsOpen=true; }            return true; }        return Super. ontouchevent (EV); }    /*** Open Menu*/     Public voidOpenmenu () {if(IsOpen)return;  This. Smoothscrollto (0, 0); IsOpen=true; }    /*** Close Menu*/     Public voidClosemenu () {if(isOpen) { This. Smoothscrollto (mmenuwidth, 0); IsOpen=false; }    }    /*** Toggle Menu Status*/     Public voidToggle () {if(IsOpen) {closemenu (); } Else{openmenu (); }    }}

Android Custom slide-up panel

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.