Home > Java > javaTutorial > body text

Android component DrawerLayout implements drawer menu

高洛峰
Release: 2017-01-07 14:38:46
Original
1239 people have browsed it

The DrawerLayout component is also a component in the V4 package and is directly inherited from the ViewGroup class, so this class is also a container class.

The placement and layout of the drawer menu is controlled by the android:layout_gravity attribute. The optional values ​​are left, right or start and end. If you layout through xml, you need to use DrawerLayout as the parent container, the group interface layout as its first child node, and the drawer layout as the second child node. In this way, the content display area and drawer menu area Independently, you only need to set the content for the two areas separately. Android provides some practical listeners, and overloading related callback methods can write logical business during the interaction process of the menu.

Using DrawerLayout can easily achieve the drawer effect. The steps for using DrawerLayout are as follows:

1) In DrawerLayout, the first sub-View must be the view that displays the content, and set Its layout_width and layout_height attributes are match_parent.

2) The second view is a drawer view, and the attribute layout_gravity="left|right" is set to indicate whether to slide out from the left or right. Set its layout_height="match_parent"

eg:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="content" />
<ListView
android:id="@+id/listview"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#FFB5C5" />
</android.support.v4.widget.DrawerLayout>
Copy after login

The effect achieved:

Android component DrawerLayout implements drawer menu

The above is what the editor gives you The Android component DrawerLayout introduced the relevant knowledge of implementing the drawer menu, I hope it will be helpful to everyone.

For more Android component DrawerLayout implementation of drawer menu related articles, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!