DrawerLayout的openDrawer()和closeDrawer()方法


如下代碼

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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM