SlidingMenu slide menu of Android UI

Source: Internet
Author: User

SlidingMenu slide menu of Android UI
The SlidingMenu slide menu is a relatively new setting interface or configuration interface effect. It is displayed on the left or right sliding of the main interface to facilitate various operations. Many excellent applications use this interface scheme, such as facebook, Renren, everynote, Google +, Netease news, zhihu daily, youdao cloud notes, and so on.

Nowadays, this interaction method is becoming more and more popular. Although this interaction method can be implemented by using custom components, it is easier to use third-party open-source libraries. Address: https://github.com/jfeinstein10/SlidingMenu.git

Implementation principle of the slide menu:
There must be two parts in the layout of an Activity. One is the layout of menus and the other is the layout of content. The two la s are arranged horizontally. The menu is left and the content is right. During initialization, the menu layout is shifted to the left to be completely hidden, so that the content layout is fully displayed in the Activity. Then, the left offset distance of the menu layout is changed by listening to the finger sliding event to control the display and hiding of the menu layout.

Instance:
Running effect:


To achieve SlidingMenu, you must first import it to your project as libary. The directory structure is as follows:



Code List:
Main Interface content layout: activity_main.xml

     
  
 
Slide menu layout: slidingmenu. xml
     
  
 

Size resource file: dimens. xml
     
      
  
   16dp
      
  
   16dp
      
  
   150dp
      
  
   15dp
  
 

Shadow. xml Resource: This resource file is used to implement shadow effects. It uses a gradient drawing effect.
 
     
  
 

Java source code file: MainActivity. java
Package com. rainsong. slidingmenudemo; import android. OS. bundle; import android. app. activity; import android. view. menu; import com. jeremyfeinstein. slidingmenu. lib. slidingMenu; public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // instantiate the slide menu object SlidingMenu menu = new SlidingMenu (this); // set it to the left slide menu. setMode (SlidingMenu. LEFT); // set the touch screen mode menu. setTouchModeAbove (sregistringmenu. TOUCHMODE_FULLSCREEN); // you can specify the width of the sliding shadow. setShadowWidthRes (R. dimen. shadow_width); // sets the image resource menu of the sliding shadow. setShadowDrawable (R. drawable. shadow); // set the remaining width menu displayed on the home page when the sliding menu is drawn. setBehindOffsetRes (R. dimen. slidingmenu_offset); // set the value of the gradient effect menu. setFadeDegree (0.35f); // attaches the menu to the Activity. attachToActivity (this, SlidingMenu. SLIDING_CONTENT); // you can specify the layout of the sliding menu. setMenu (R. layout. sshortingmenu) ;}@ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}



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.