Android Imitation NetEase client implements drawer-style drag-and-drop menu interface

Source: Internet
Author: User

There is an article written in front of the use of drawerlayout to achieve the Android imitation NetEase client drawer mode, yesterday from the group to see a buddy asked drawer pull, from the bottom of the main interface appears, while using drawerlayout to achieve is to cover the main interface, Today we will implement the main interface below the popup menu interface, first, easy to watch


Ah oh, the picture is so big, start today's realization


1. Inheriting Horizontalscrollview, implementing custom Controls

Package Com.sdufe.thea.guo.view;import Com.nineoldandroids.view.viewhelper;import Android.content.context;import Android.util.attributeset;import Android.util.displaymetrics;import Android.util.typedvalue;import Android.view.motionevent;import Android.view.viewgroup;import Android.view.windowmanager;import Android.widget.horizontalscrollview;import Android.widget.linearlayout;public class SlidingMenu extends Horizontalscrollview {private LinearLayout mwapper;private viewgroup mmenu;private viewgroup mContent;/** * Screen width */  private int msreenwidth;/** * Menu distance to right width, unit dp */private int mmenurightpadding=100;/** * menu width */private int mmenuwidth;/** * Ok onmeasure only draws once */private Boolean once;public slidingmenu (context context, AttributeSet attrs, int defstyle) {super (con Text, Attrs, Defstyle); WindowManager WindowManager = (WindowManager) context.getsystemservice (context. Window_service);D isplaymetrics outmetrics=new displaymetrics (), Windowmanager.getdefaultdisplay (). GetMetrics ( Outmetrics); Msreenwidth=outmetrics.widthpixels;/** * Convert DP to px */mmenurightpadding = (int) typedvalue.applydimension (typedvalue.complex_ Unit_dip, Getresources (). Getdisplaymetrics ());} Public Slidingmenu (context context, AttributeSet Attrs) {This (context, attrs, 0);} Public Slidingmenu (Context context) {This (context, null);} /** * OK width/@Overrideprotected void onmeasure (int widthmeasurespec, int heightmeasurespec) {super.onmeasure ( Widthmeasurespec, Heightmeasurespec); if (!once) {mwapper= (linearlayout) getchildat (0); mmenu= (ViewGroup) Mwapper.getchildat (0); mcontent= (ViewGroup) Mwapper.getchildat (1);/** * Menu setting width */mmenuwidth=mmenu.getlayoutparams () . width=msreenwidth-mmenurightpadding;/** * Content Set width */mcontent.getlayoutparams (). width=msreenwidth;once=true;}} /** * Set Offset, hide menu */@Overrideprotected void OnLayout (Boolean changed, int l, int t, int r, int b) {super.onlayout (changed , L, T, R, B), if (changed) {/** * Instant complete Hide */this.scrollto (mmenuwidth, 0);}} @Overridepublic boolean ontouchevent (motionevent ev) {switch(Ev.getaction ()) {Case motionevent.action_up:/** * hidden part width */int scroll=getscrollx (); if (SCROLL>MMENUWIDTH/2) {/** * animation implementation Hidden */ Smoothscrollto (mmenuwidth, 0);} else {/** * Animation implementation displays */smoothscrollto (0, 0);} return true;} return super.ontouchevent (EV);} /** * Drawer-style sliding via onscrollchanged */@Overrideprotected void onscrollchanged (int l, int t, int oldl, int Oldt) {Super.onscroll Changed (L, T, OLDL, Oldt); Viewhelper.settranslationx (Mmenu, L);}}

Get the width of the screen in the constructor and convert the DP unit mmenurightpadding to PX

Assigning wide and high values to Onmeasure

Determine location in OnLayout

Control gestures in Ontouch

Onscrollchanged Implement drawer animation, here reference Nineold animation package, compatible with 3.0 version

The rest of the code in the comments are very clear, here is not nonsense, to this almost achieved, the following is used,

<com.sdufe.thea.guo.view.slidingmenu xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns: tools= "Http://schemas.android.com/tools"    android:layout_width= "match_parent"    android:layout_height= " Match_parent ">    <linearlayout        android:layout_width=" match_parent "        android:layout_height=" Match_parent "        android:orientation=" Horizontal ">        <include layout=" @layout/layout_menu "/>        <linearlayout            android:layout_width= "match_parent"            android:layout_height= "Match_parent            " android:background= "@drawable/monkey"            android:orientation= "vertical" >        </LinearLayout>    </LinearLayout></com.sdufe.thea.guo.view.SlidingMenu>

OK, end, the above code modified from Yang QQ slide, slightly different only


Code: http://download.csdn.net/detail/elinavampire/8276537


Android Imitation NetEase Client implements drawer Drag menu interface

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.