Android侧滑菜单(DrawerLayout)的学习

侧滑菜单的简单使用;DrawerLayout android提供的侧滑菜单,能够实现 目录推出,就是大家常见的效果,效果图如下;

这里写图片描述

DrawerLayout 的使用非常简单;只要你提供布局就好;
一个左边的布局,一个显示内容的布局;
布局文件 代码如下所示

1<android.support.v4.widget.DrawerLayout 2xmlns:android="http://schemas.android.com/apk/res/android" 3android:id="@+id/drawer_layout" 4android:layout_width="match_parent" 5android:layout_height="match_parent"> 6 7//左边 8<include layout="@layout/activity_content"/> 9//内容 10<include layout="@layout/activity_left_content"/> 11 12</android.support.v4.widget.DrawerLayout>

java 代码 控制; DrawerLayout 已经封装好了手势滑动,如果想要隐藏左边的目录,通过

mDrawerLayout.closeDrawer(mLView);

即可 手动隐藏;

DrawerLayout的使用就是这么简单;接下来我稍微说一下我写的这个例子

1、界面

左边导航布局

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:layout_gravity="start" 7 android:background="#FBFBFB" 8 android:id="@+id/left_view" 9 10 > 11 <android.support.v7.widget.Toolbar 12 android:layout_width="match_parent" 13 android:layout_height="wrap_content" 14 android:id="@+id/left_tool" 15 android:background="#AA88FF" 16 17 > 18 19 </android.support.v7.widget.Toolbar> 20 21 <android.support.v7.widget.RecyclerView 22 android:id="@+id/left_recyclerView" 23 android:layout_width="match_parent" 24 android:layout_height="match_parent" 25 > 26 27 28 </android.support.v7.widget.RecyclerView> 29 30</LinearLayout>

内容布局

1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFF99" > 3 <android.support.v7.widget.Toolbar android:id="@+id/center_content_tool" android:layout_width="match_parent" android:layout_height="40dp" android:background="@color/colorLilac" android:title="断言" > 4 5 </android.support.v7.widget.Toolbar> 6 <FrameLayout android:id="@+id/center_content_frame" android:layout_width="match_parent" android:layout_height="match_parent"></FrameLayout> 7 8</LinearLayout>

2、主要代码

1/** * 根据向导加载内容,默认为第一个 * @param position */ 2 public void loadCenterContent(int position){ 3 String title=guides.get(position).getmTitle(); 4 mCenterTool.setTitle(title); 5 String content=readStringFromAssert(guides.get(position).getGuideName()); 6 Content_Fragment fragment=Content_Fragment.newInstance(title,content); 7 getFragmentManager().beginTransaction().replace(R.id.center_content_frame, 8 fragment).commit(); 9 10 mDrawerLayout.closeDrawer(mLView);11 12protected void initUIData(){ 13 mLeftToolbar.setTitle("android学习手册"); 14 //默认加载第一项 15 loadCenterContent(0); 16 17 RecyclerView.LayoutManager manager=new LinearLayoutManager(this); 18 mLeftView.setLayoutManager(manager); 19 mLeftView.setAdapter(new LeftAdapter(guides, new ItemClickListener() { 20 @Override 21 public void onItemClick(View view, int position) { 22 //当前选个哪个就加载其内容 23 loadCenterContent(position); 24 } 25 @Override 26 public void onLongItemClick(View view, int position) { 27 Log.i(TAG, "onLongItemClick: "); 28 } 29 })); 30 31 32 33 34 } 35 36 /** * 初始化目录列表内容 */ 37 protected void initList(){ 38 guides.add(new Guide("断言","断言的学习及使用","asserts.txt")); 39 guides.add(new Guide("NDK","android studio 中 NDK的使用","ndk study.txt")); 40 guides.add(new Guide("mac command","mac 下常用的终端命令","command")); 41 guides.add(new Guide("二维码的生成与识别","通过zxing生成二维码与识别二维码","zxing")); 42 43 44 }

总结

使用别人写好的框架是一个非常非常容易的事 ;自己写,也可以进步

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )