Android使用DrawerLayout实现侧滑菜单效果-创新互联

一、概述

创新互联于2013年开始,先为昌图等服务建站,昌图等地企业,进行企业商务咨询服务。为昌图企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

DrawerLayout是一个可以方便的实现Android侧滑菜单的组件,我最近开发的项目中也有一个侧滑菜单的功能,于是DrawerLayout就派上用场了。如果你从未使用过DrawerLayout,那么本篇博客将使用一个简单的案例带你迅速掌握DrawerLayout的用法。

二、效果图

三、代码实现

主布局activity_main.xml


<?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"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@android:color/white"
 android:fitsSystemWindows="true"
 android:orientation="vertical">

 <android.support.v7.widget.Toolbar
 android:id="@+id/toolbar"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@color/blueStatus"
 android:minHeight="?attr/actionBarSize"
 app:navigationIcon="?attr/homeAsUpIndicator"
 app:theme="@style/Theme.AppCompat.NoActionBar">

 </android.support.v7.widget.Toolbar>


 <include layout="@layout/title_layout" />

 <android.support.v4.widget.DrawerLayout xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/drawer_layout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:openDrawer="start">

 <ListView
  android:id="@+id/listView"
  android:layout_width="match_parent"
  android:layout_height="match_parent" />

 <LinearLayout
  android:layout_width="260dp"
  android:layout_height="match_parent"
  android:layout_gravity="right">

  <include layout="@layout/drawer_content" />
 </LinearLayout>
 </android.support.v4.widget.DrawerLayout>
</LinearLayout>

分享文章:Android使用DrawerLayout实现侧滑菜单效果-创新互联
网页链接:https://www.cdcxhl.com/article30/hjoso.html

成都网站建设公司_创新互联,为您提供网站制作虚拟主机网站设计公司用户体验手机网站建设外贸网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都做网站