首页 > 其他 > 详细

DrawerLayout的openDrawer()和closeDrawer()方法

时间:2016-02-22 23:28:05      阅读:2752      评论:0      收藏:0      [点我收藏+]

如下代码

DrawerLayout mdrawerLayout;

Button btn;

-----------------------------------------------------------------------------------------------------------------------以上为声明组件,为简便其余过程省略

btn.setOnClickListener(new OnClickListener(){

      mdrawerLayout.openDrawer(Gravity.LEFT);//这里设置的方向应该跟下面xml文件里面的gravity方向相同,不然会报错,start和LEFT都为从左边出现

      mdrawerLayout.closDrawers();//没有参数,关闭所有的出现的抽屉

});

-----------------------------------------------------下面是drawerLayout.xml----------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dl_left"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--主界面剩余的布局将在以下进行-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"/>
</LinearLayout>
<!--抽屉拉开后的布局,即ListView所在的布局-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="start">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv_left_menu"
android:divider="@null">
</ListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

DrawerLayout的openDrawer()和closeDrawer()方法

原文:http://www.cnblogs.com/Cc1231/p/5208444.html

(1)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!