Let's focus on the Android drawer navigation Navigationdrawer. First of all to perceptual the effect of this bar:
Looking at a lot of applications, I think this slippery drawer effect of the menu is very good. Do not have to switch to another page, also do not have to press the menu hardware button, directly in the interface of a button click, the menu slide out, and feel able to put a lot of things.
The simplest is to use the official drawer navigation navigationdrawerlayout to achieve. Drawerlayout This class is in the support library, you need to add Android-support-v4.jar this package. Then import the import android.support.v4.widget.DrawerLayout in front of the program;
If you can't find this class, first update the Android Support Library with the SDK manager, and then on the Android sdk\extras\android\support\ Locate the Android-support-v4.jar under the V4 path, copy the Libs path to the project, and add it to the build path.
When you create a new Android project, you can choose to use navigation Drawer:
Let's take a quick look at the code, first Navigationdrawerfragment.java the class, which layout files are loaded.
@Override public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {//pumping Drawer ListView Find the corresponding XML layout Mdrawerlistview = (ListView) inflater.inflate (R.layout.fragment_navigation_drawer, container,
FALSE); ListView the drawer to a fixed point hit listener, click on the click of the selected item Mdrawerlistview.setonitemclicklistener (new Adapterview.onitemclicklistener () {@Ov Erride public void Onitemclick (adapterview<?> parent, view view, int position, long id) {SelectItem (posit
ION);
}
}); Bind an adapter to the drawer ListView mdrawerlistview.setadapter (New Arrayadapter<string> (Getactionbar). Getthemedcontext () Android. R.layout.simple_list_item_activated_1, Android. R.ID.TEXT1, New string[]{getString (R.string.title_section1), getString (R.string.title_section2) , GetString (R.string.title_section3), getString (R.string.title_section4), getString (r.string
. title_section5),}); MdraweRlistview.setadapter (New Draweradapter (Getactivity ()));
Sets the drawer ListView to show the appearance of a selected item.
Mdrawerlistview.setitemchecked (Mcurrentselectedposition, true);
Will handle the drawer ListView back to return Mdrawerlistview;
}
Navigationdrawer is mainly a ListView, this ListView uses fragment_navigation_drawer.xml:
<listview 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 "
android:background= "@color/image_bg_green"
android:choicemode= "Singlechoice"
android:divider= "@ Color/image_bg_lightgreen "
android:dividerheight=" 1DP "
tools:context=" net.nowamagic.magicapp_v7. Navigationdrawerfragment "/>
This ListView is the ListView that the drawer navigation intuitively sees. At the same time, each grid in ListView is populated by a relative layout, and its XML is fragment_main.xml:
<relativelayout 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 "
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_ Horizontal_margin "
android:paddingright=" @dimen/activity_horizontal_margin "
android:paddingtop=" @dimen /activity_vertical_margin "
tools:context=" net.nowamagic.magicapp_v7. Mainactivity$placeholderfragment ">
<textview
android:id=" @+id/section_label "
android: Layout_width= "Wrap_content"
android:layout_height= "wrap_content"/>
</RelativeLayout>
Create a new navigationdrawer based project with the following effect:
The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.