侧滑栏DrawerLayout的简单使用
16lz
2021-01-23
大家可以把DrawerLayout 当成LinearLayout 等使用,主要注意两点:
1.添加布局 android.support.v4.widget.DrawerLayout 。
2.在DrawerLayout 下,设置底层布局和侧滑栏布局,同时设置侧滑栏效果android:layout_gravity,start 和end (left|right)即从左往右还是 从右往左出现。
<?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" xmlns: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:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button"/> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorAccent" android:fitsSystemWindows="true" android:layout_gravity="start">LinearLayout>android.support.v4.widget.DrawerLayout>
通过以上xml文件,就可以实现DrawerLayout效果,再根据业务功能实现侧滑栏布局等。
PS:当侧滑栏没数据时,可能会出现卡顿,有数据以后就没问题了!!
更多相关文章
- Android Developers:在SQL数据库中保存数据
- Android页面跳转以及数据传递实现
- Android实现渐显按钮的左右滑动效果
- android编辑布局文件时非要降低api level或者更改主题才能显示布
- Android 线性布局:LinearLayout
- Android学习笔记-Android非布局activity中布局文件及控件加载方