Android open-source project SlidingMenu Study Notes (1), androidslidingmenu

Source: Internet
Author: User

Android open-source project SlidingMenu Study Notes (1), androidslidingmenu

SlidingMenu is a popular UI Technology in applications, which can achieve a dazzling sliding effect. SlidingMenu is a Project hosted on Git and is open-source and free of charge, slidingMenu is imported to the required project as a Library. SlidingMenu may be implemented in different ways in the future. You can download it at the following address.

Git project hosting address for the SlidingMenu: https://github.com/jfeinstein10/SlidingMenu

Demo directory structure:




Key code:

MainActivity. java

Package com. dzt. slidingmenudemo; import android. OS. bundle; import android. support. v4.app. fragmentActivity; import com. slidingmenu. lib. sshortingmenu; public class MainActivity extends FragmentActivity {private sshortingmenu mChannelMenu; @ Overridepublic void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); // set the title of the title bar setTitle ("test SlidingMenu"); setConten TView (R. layout. main_activity); initChannelMenu ();} private void initChannelMenu () {// create the SlidingMenu object mChannelMenu = new SlidingMenu (this); // set the position of the slide menu, which is on the left. When the menu is pulled, mChannelMenu is displayed on the left. setMode (SlidingMenu. LEFT); // set the touch range. Here, the full screen mChannelMenu is set. setTouchModeAbove (sregistringmenu. TOUCHMODE_FULLSCREEN); // set the shadow width. Check the second one on the top and place it on the right. There is a shadow transition. This is the mChannelMenu. setShadowWidthRes (R. dimen. shadow_width); // specifies the shadow effect. You can set an image or a color transition mChannelMenu. setShadowDrawable (R. drawable. shadow); // set the spacing between the backend and the sliding column and the original interface. setBehindOffsetRes (R. dimen. slidingmenu_offset); // border angle. mChannelMenu indicates the border. setFadeDegree (0.35f); // sets the mChannelMenu mode for the touch screen. setTouchModeAbove (sregistringmenu. TOUCHMODE_FULLSCREEN); // associate the slide bar with the current ActivitymChannelMenu. attachToActivity (this, SlidingMenu. SLIDING_CONTENT); // The layout file mChannelMenu in the slide bar. setMenu (R. layout. channel_slide_menu); getSupportFragmentManager (). beginTransaction (). replace (R. id. menu_frame, new MyListFragment ()). commit () ;}@ Overridepublic void onBackPressed () {if (mChannelMenu. isMenuShowing () {// hide the SlidingMenu. The Content here is our main ActivitymChannelMenu. showContent ();} else {super. onBackPressed ();}}}
MyListFragment. java

Package com. dzt. slidingmenudemo; import android. content. context; import android. OS. bundle; import android. support. v4.app. listFragment; import android. view. layoutInflater; import android. view. view; import android. view. viewGroup; import android. widget. arrayAdapter; import android. widget. imageView; import android. widget. textView; public class MyListFragment extends ListFragment {public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {return inflater. inflate (R. layout. list, null);} public void onActivityCreated (Bundle savedInstanceState) {super. onActivityCreated (savedInstanceState); SampleAdapter adapter = new SampleAdapter (getActivity (); for (int I = 0; I <20; I ++) {adapter. add (new SampleItem ("list on the left", android. r. drawable. ic_menu_search);} setListAdapter (adapter);} private class SampleItem {public String tag; public int iconRes; public SampleItem (String tag, int iconRes) {this. tag = tag; this. iconRes = iconRes;} public class SampleAdapter extends ArrayAdapter <SampleItem> {public SampleAdapter (Context context) {super (context, 0);} public View getView (int position, View convertView, viewGroup parent) {if (convertView = null) {convertView = LayoutInflater. from (getContext ()). inflate (R. layout. item, null);} ImageView icon = (ImageView) convertView. findViewById (R. id. row_icon); icon. setImageResource (getItem (position ). iconRes); TextView title = (TextView) convertView. findViewById (R. id. row_title); title. setText (getItem (position ). tag); return convertView ;}}}

One thing to note, in the use of the project will be generated by default: android-support-v4.jar, there may be conflicts with SlidingMenu, need to delete, otherwise it will report an error.

Sample Code: http://download.csdn.net/detail/deng0zhaotai/7856011
The latest SlidingMenu can be downloaded from Git.


Now, is it better for android to use the SlidingMenu open-source project to slide the menu bar, or is it better to use the Navigation Drawer that comes with android?

If you are learning the code, it is recommended to study the official version. However, SlidingMenu has many functions, such as controlling the background behind the menu when sliding out. It seems that the background of Navigation Drawer cannot be moved. It is a trend to replace open-source projects with official APIs, because everyone thinks that official interfaces are safe to use, but open-source projects may be more flexible.

For android open-source projects, if you want to join an open-source project to learn and train yourself

You can do it ,,,
 

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.