DrawerLayout
DrawerLayout是Support Library包中实现了侧滑菜单效果的控件。今天才发现使用起来这么简单。先看效果
再看代码:
只需要在根布局写成DrawerLayout就行,因为他本身就带有滑动的效果
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.drawerlayout.MainActivity"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="Hello World!" /> </FrameLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/colorPrimary" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="策略1" android:textColor="#ff0" android:textSize="30sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="策略2" android:textColor="#f00" android:textSize="30sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="策略3" android:textColor="#0f0" android:textSize="30sp" /> </LinearLayout> </android.support.v4.widget.DrawerLayout>