您的位置:首页 > 移动开发 > Android开发

Android之DrawerLayout的简单使用

2018-01-12 18:03 330 查看
布局文件最好用DrawerLayout作为根布局,上面是主布局,下面是侧滑布局,注意一定要有layout_gravity
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.zhihupaper.MainActivity">

<!--主布局-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />

<!--侧滑栏-->
<include layout="@layout/left_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>

</android.support.v4.widget.DrawerLayout>
通过点击方式打开DrawerLayout的api,注意这里的Gravity就是侧滑栏中设置的layout_gravity
((DrawerLayout)root).openDrawer(Gravity.START);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: