Android-like Netease client implements drawer-style drag menu interface and android-like Netease

Source: Internet
Author: User

Android-like Netease client implements drawer-style drag menu interface and android-like Netease

I have previously written an article using DrawerLayout to implement the drawer mode of the Android-like Netease client. Yesterday I saw a guy asking about drawer-style drag from the group, which appeared below the main interface, drawerLayout is used to overwrite the main interface. Today, we will implement the menu interface at the bottom of the main interface to facilitate viewing.


Ah, the picture is so big that today's implementation starts.


1. inherit from HorizontalScrollView to implement 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 SlidingMe Nu extends HorizontalScrollView {private LinearLayout mWapper; private ViewGroup mMenu; private ViewGroup mContent;/*** screen width */private int mSreenWidth;/*** the width from the menu to the right, unit: dp */private int mMenuRightPadding = 100;/*** menu width */private int mMenuWidth;/*** determine that onMeasure is drawn only once */private boolean once; public SlidingMenu (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle); WindowMa Nager windowManager = (WindowManager) context. getSystemService (context. WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics (); windowManager. getdefadisplay display (). getMetrics (outMetrics); mSreenWidth = outMetrics. widthPixels;/*** converts dp to px */mMenuRightPadding = (int) TypedValue. applyDimension (TypedValue. COMPLEX_UNIT_DIP, 100, getResources (). getDisplayMetrics ();} public SlidingMenu (Context context, AttributeSet attrs) {this (context, attrs, 0);} public SlidingMenu (Context context) {this (context, null );} /*** determine width and height */@ 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 Setting width */mContent. getLayoutParams (). width = mSreenWidth; once = true ;}/ *** sets the offset to hide menu */@ Overrideprotected void onLayout (boolean changed, int l, int t, int r, int B) {super. onLayout (changed, l, t, r, B); if (changed) {/*** instantly hide */this. scrollTo (mMenuWidth, 0) ;}@ Overridepublic boolean onTouchEvent (MotionEvent ev) {switch (ev. getAction () {case MotionEvent. ACTION_UP:/*** hide part width */int scroll = getScrollX (); if (scroll> mMenuWidth/2) {/*** hide animation */smoothScrollTo (mMenuWidth, 0);} else {/*** animation display */smoothScrollTo (0, 0);} return true;} return super. onTouchEvent (ev);}/*** implements Drawer Sliding through onScrollChanged */@ Overrideprotected void onScrollChanged (int l, int t, int oldl, int oldt) {super. onScrollChanged (l, t, oldl, oldt); ViewHelper. setTranslationX (mMenu, l );}}

Obtain the screen width in the constructor and convert the mMenuRightPadding unit of dp to px.

Assign a value to the width and height in onMeasure

OnLayout

Controlling gestures in onTouch

OnScrollChanged implements drawer animation. The nineold animation package is referenced here. It is compatible with version 3.0.

The comments in the remaining part of the code are clearly explained, so we will not talk about it here, so we will almost implement it here, and we will use it below,

<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 is modified from the qq slide of Hongyang, which is slightly different.


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


Related Article

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.