您的位置:首页 > 移动开发 > Android开发

Elyar的Android笔记(七):Android侧滑菜单

2015-03-28 18:45 253 查看

Elyar的Android笔记(七):Android侧滑菜单

转载前请注明出处,尊重版权:http://blog.csdn.net/u012418084

      首先明确几点内容:

实现侧滑需要使用:DrawerLayout,它在android.support.v4.widget包中
主布局容器:用来显示主要的布局内容
侧滑菜单容器:用来存放侧滑菜单中的子View


     DrawerLayout中包含两个子元素,第一个为主布局中显示的内容,第二个为侧滑菜单中显示的内容

    <android.support.v4.widget.DrawerLayout 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"

           tools:context=".MainActivity" >

         <LinearLayout

              android:layout_width="match_parent"

              android:layout_height="match_parent" >

             (1)<include layout="@layout/XXXX" />

         //包含主布局显示内容

         </LinearLayout>

         <LinearLayout

              android:layout_width="240dp"

              android:layout_height="match_parent"

             (2)android:layout_gravity="start|right|">

              <include layout="@layout/XXXX" />

          //包含侧滑菜单显示内容

         </LinearLayout>

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

   注:(1)如果主布局内容和侧滑菜单内容复杂,那么可以以include的方式引入到各自相应的布局中

      (2)android:layout_gravity该属性决定侧滑菜单从哪个方向滑出:start或left为从左侧滑出end或right为从右侧滑出

    完成以上步骤可以实现滑动了

    =====================================================================================================================================================

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息