DrawerLayout

DrawerLayout是Android中的一个控件,效果是一个侧拉的效果。有两部分组成,一个侧拉的布局,一个是主页面的布局。
1.在布局文件中定义DrawerLayout控件
2.设置侧拉的方向, android:layout_gravity=”start”,表示从左向右
start换为end则是从右向左

这里写图片描述

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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="wangxuewei.bwie.com.week3.MainActivity">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <FrameLayout
                android:id="@+id/fr_main"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"></FrameLayout>

            <RadioGroup
                android:id="@+id/rg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/rb_shouye"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_select"
                    android:button="@null"
                    android:checked="true"
                    android:gravity="center"
                    android:text="首页" />

                <RadioButton
                    android:id="@+id/rb_faxian"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_select"
                    android:button="@null"
                    android:gravity="center"
                    android:text="发现" />

                <RadioButton
                    android:id="@+id/rb_xiazai"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_select"
                    android:button="@null"
                    android:gravity="center"
                    android:text="下载" />

                <RadioButton
                    android:id="@+id/rb_wode"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_select"
                    android:button="@null"
                    android:gravity="center"
                    android:text="我的" />

            </RadioGroup>


        </LinearLayout>

        <LinearLayout
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="#fff"
            android:gravity="center"
            android:orientation="vertical">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="钱包" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="行程记录" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="好友邀请" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="设置" />
        </LinearLayout>

    </android.support.v4.widget.DrawerLayout>


</LinearLayout>

效果展示,效果比较丑,里面的布局都是可以自己定义的,正常布局就可以了。
这里写图片描述

drawerLayout.closeDrawer(侧拉布局的id); 关闭菜单
drawerLayout.openDrawer(侧拉布局的id);打开菜单

监听事件
drawerLayout.setDrawerListener

更多详情,请参考:http://blog.youkuaiyun.com/liujiawei00/article/details/51427098

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值