DrawerLayout的基本使用

来源:互联网 发布:软件试用报告模板 编辑:程序博客网 时间:2024/06/14 06:29
使用DrawerLayout的步骤有以下1几点:

1)在DrawerLayout中,第一个子View必须是显示内容的view,并且设置它的layout_width和layout_height属性是match_parent.

2)第二个view是抽屉view,并且设置属性layout_gravity="left|right",表示是从左边滑出还是右边滑出。设置它的layout_height="match_parent"


  1. <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:id="@+id/drawerlayout"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     tools:context=".MainActivity" >  
  7.    
  8.     <TextView  
  9.         android:id="@+id/textview"  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="match_parent"  
  12.         android:gravity="center"  
  13.         android:text="content" />  
  14.    
  15.     <ListView  
  16.         android:id="@+id/listview"  
  17.         android:layout_width="80dp"  
  18.         android:layout_height="match_parent"  
  19.         android:layout_gravity="left"  
  20.         android:background="#FFB5C5" />  
  21.    
  22. </android.support.v4.widget.DrawerLayout> 
这就可以实现侧拉菜单了,接下来的ListView适配器就不粘出来了,很简单的一种实现思路。

原创粉丝点击