Drawerlayout simple use of Android Design support controls

Source: Internet
Author: User

Drawerlayout allows us to easily implement the side-slip menu effect in the project. Today, mainstream applications such as QQ are
The use of such an effect.

These two days are also learning about Android Design support. There are very many articles about this in the Internet. But in order to facilitate later use, or the knowledge of learning to make a simple record. This time the code is also the layout and code added on the basis of the tablayout that was introduced in the previous blog Android Design support control.
Main interface layout:

<?xml version= "1.0" encoding= "Utf-8"?><android.support.v4.widget.drawerlayout  xmlns:android  =" http://schemas.android.com/apk/res/android "  xmlns:app  = "http://schemas.android.com/apk/ Res-auto " android:id  =" @+id/drawer_view "     android:layout_width  = "match_parent"  android:layout_height  = "match_parent"  >     <android.support.design.widget.NavigationViewandroid:id="@+id/navigation_view"  android:layout_width="200DP"android:layout_height="Match_parent"  Android:layout_gravity="Left"android:fitssystemwindows="true"app: Headerlayout="@layout/content_main">                                                <!--Content_main the same as in the previous article --    </android.support.design.widget.NavigationView></android.support.v4.widget.DrawerLayout>

Layout on the left side of the slide menu

<?xml version="1.0" encoding="utf-8"?

><linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns:app =" Http://schemas.android.com/apk/res-auto " Span class= "Hljs-attribute" >android:layout_width = "match_parent" android:layout_height = "match_parent" android:orientation =" vertical " android:padding = "10DP" ; <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margintop = "40DP" android:text =" menu One "/> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margintop = "20DP" android:text =" menu, "/> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margintop = "20DP" android:text =" menu three "/> <textview android:layout _width = "wrap_content" android:layout_height = "wrap_content" android:layout_margintop = "20DP" android:text =" menu four "/> <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" android:layout_margintop="20DP"android:text="Menu Five" /> </linearlayout>

Fragment Interface Layout

<?

XML version= "1.0" encoding= "Utf-8"?><linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns:app =" Http://schemas.android.com/apk/res-auto " Span class= "Hljs-attribute" >android:layout_width = "match_parent" android:layout_height = "match_parent" android:orientation =" vertical " android:padding = "10DP" ; <TextViewandroid:id="@+id/content_tv"android:layout_width="Wrap _content "android:layout_height="wrap_content "android:layout_margintop=" 40DP "android:text=" menu One " /> </linearlayout>

The main interface code, Testadapter and Testfragment code are also the same as an article.

 Public  class mainactivity extends fragmentactivity {    //Easy to implement label display    PrivateTablayout tab_layout;PrivateViewpager Viewpager;PrivateTestadapter Madapter;PrivateList<fragment> fragments;PrivateList<string> titles;PrivateDrawerlayout Drawer_view;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (r.layout.drawer_layout);        Initviews ();    Initviewpages (); }Private void initviewpages() {fragments =NewArraylist<> (); Titles =NewArraylist<> (); for(inti =0; I <4; i++) {String title="tab"+ i;            Titles.add (title); Tab_layout.addtab (Tab_layout.newtab (). SetText (title));//Add tab titleFragment Fragment =NewTestfragment (); Bundle bundle =NewBundle (); Bundle.putstring ("Content","This is the first"+ i +"A fragment page");            Fragment.setarguments (bundle);        Fragments.add (fragment); } Madapter =NewTestadapter ( This. Getsupportfragmentmanager (), titles, fragments);        Viewpager.setadapter (Madapter);        Tab_layout.setupwithviewpager (Viewpager);    Tab_layout.settabsfrompageradapter (Madapter); }Private void initviews() {tab_layout = (tablayout) Findviewbyid (r.id.tab_layout);        Viewpager = (Viewpager) Findviewbyid (R.id.viewpager);        drawer_view= (drawerlayout) Findviewbyid (R.id.drawer_view);    Drawer_view.closedrawer (Gravitycompat.start); }}


Drawerlayout simple use of Android Design support controls

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.