Recently saw a project on the sidebar from GitHub, mimicking the QQ sidebar.
The GitHub address is https://github.com/SpecialCyCi/AndroidResideMenu, This project is an Android studio project that can be imported into Android studio or imported into eclipse.
The Residemenu is a third-party control that is written and can be used directly. Let's take a look at how it's used.
public class Menuactivity extends fragmentactivity implements view.onclicklistener{private Residemenu residemenu; Private Menuactivity Mcontext; Private Residemenuitem Itemhome; Private Residemenuitem Itemprofile; Private Residemenuitem Itemcalendar; Private Residemenuitem itemsettings; /** * Called when the activity is first created. */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Mcontext = this; Setupmenu (); if (savedinstancestate = = null) changefragment (new Homefragment ()); } private void Setupmenu () {//attach to current activity; Residemenu = new Residemenu (this); Residemenu.setbackground (R.drawable.menu_background); Residemenu.attachtoactivity (this); Residemenu.setmenulistener (Menulistener); Valid scale factor is between 0.0f and 1.0f. Leftmenu ' width is 150dip. Residemenu.setscalevalue (0.6f); Create menu items; Itemhome = new Residemenuitem (this, r.drawable.icon_home, "home"); Itemprofile = new Residemenuitem (this, r.drawable.icon_profile, "profile"); Itemcalendar = new Residemenuitem (this, R.drawable.icon_calendar, "Calendar"); Itemsettings = new Residemenuitem (this, r.drawable.icon_settings, "settings"); Itemhome.setonclicklistener (this); Itemprofile.setonclicklistener (this); Itemcalendar.setonclicklistener (this); Itemsettings.setonclicklistener (this); Residemenu.addmenuitem (Itemhome, residemenu.direction_left); Residemenu.addmenuitem (Itemprofile, residemenu.direction_left); Residemenu.addmenuitem (Itemcalendar, residemenu.direction_right); Residemenu.addmenuitem (Itemsettings, residemenu.direction_right); You can disable a direction by setting//Residemenu.setswipedirectiondisable (residemenu.direction_right); Findviewbyid (R.id.title_bar_left_menu). Setonclicklistener (New View.onclicklistener () {@Override public void OnClick (view view) {Residemenu.openmenu (residemenu.direction_left); } }); Findviewbyid (R.id.title_bar_right_menu). Setonclicklistener (New View.onclicklistener () {@Override PU Blic void OnClick (view view) {Residemenu.openmenu (residemenu.direction_right); } });}
The Residemenuitem is the option in our sidebar, where four options are created, and the control has a left-right sidebar effect that allows you to swipe left and right. Of course we can also set options to appear in the right sidebar. The Residemenu.addmenuitem is called to set the side bar to display.
each option can be used to display different fragment. This open source project is still very good, is a more popular side bar style.
If you have any questions, you are welcome to communicate with me. to learn more about the students, you can click to view the source code , personally run the experience!
Jerry Education
Source:http://blog.csdn.net/jerehedu/
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and CSDN Common, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
Android to achieve the effect of imitation QQ side Sidebar