android自定义抽屉布局,自定义Drawer,抽屉布局

主要内容:

如何自定义Drawer的布局,比如在里面加一个ListView,以及一些需要注意到的点。

有时候可以需要一个抽屉布局来显示和隐藏一些主菜单。

在android studio里直接new -> Activity —> Navigation Drawer Activity。

这时候就可以得到一个可以运行的drawer。

修改拥有DrawerLayout的xml布局。

xmlns:app="[http://schemas.android.com/apk/res-auto](http://schemas.android.com/apk/res-auto)"

xmlns:tools="[http://schemas.android.com/tools](http://schemas.android.com/tools)"

android:id="@+id/drawer_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true"

tools:openDrawer="start">

layout="@layout/app_bar_main2"

android:layout_width="match_parent"

android:layout_height="match_parent" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#ffffff"

android:layout_gravity="start"

android:fitsSystemWindows="true"

>

layout="@layout/nav_header_main2" />

android:id="@+id/drawer_RecyclerView"

android:layout_width="match_parent"

android:layout_height="match_parent" />

直接将原来的navigation节点(DrawerLayout的第二个节点)去掉。添加自己想要自定义的布局,这里是一个LinearLayout加上里面的布局。

需要注意的是LinearLayout里要加上这两行:

android:layout_gravity="start"

android:fitsSystemWindows="true"

不然会有问题。

todos:

NaviationView是啥?有啥用?

CoordinatorLayout有啥用?为啥google推他?

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值