Android DrawerLayout基础

来源:互联网 发布:一加5 小米6 知乎 编辑:程序博客网 时间:2024/05/17 19:58
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="${relativePackage}.${activityClass}" >    <TextView        android:layout_width="fill_parent"        android:layout_height="50dp"        android:background="@android:color/darker_gray" />    <android.support.v4.widget.DrawerLayout        android:id="@+id/drawerlayout"        android:layout_width="match_parent"        android:layout_height="match_parent" >        <FrameLayout            android:id="@+id/contentFrame"            android:layout_width="match_parent"            android:layout_height="match_parent" >        </FrameLayout>        <ListView            android:id="@+id/listview"            android:layout_width="240dp"            android:layout_height="match_parent"            android:layout_gravity="start"            android:background="#ffffcc"            android:choiceMode="singleChoice"            android:divider="@android:color/transparent"            android:dividerHeight="0dp" >        </ListView>    </android.support.v4.widget.DrawerLayout></LinearLayout>

android.support.v4.widget.DrawerLayout里面第一个是主布局
第二个是抽屉布局

DrawerLayout的关闭和打开是事件是DrawerListener;

drawerLayout.setDrawerListener(new DrawerListener() {            @Override            public void onDrawerStateChanged(int arg0) {                // TODO Auto-generated method stub            }            @Override            public void onDrawerSlide(View arg0, float arg1) {                // TODO Auto-generated method stub            }            @Override            public void onDrawerOpened(View arg0) {                // TODO Auto-generated method stub            }            @Override            public void onDrawerClosed(View arg0) {                // TODO Auto-generated method stub            }        });
0 0
原创粉丝点击