您的位置:首页 > 其它

官方侧滑菜单DrawerLayout的简单实现

2017-02-10 16:27 295 查看
drawerlayout目前只支持左右滑动,如果需要上下滑动需要自定义

下面说一下代码层:

其实不需要配

mDrawerLayout=(DrawerLayout)findViewById(R.id.drawer_drawerlayout);
first=(LinearLayout)findViewById(R.id.drawer_first);
seoncd=(LinearLayout)findViewById(R.id.drawer_second);

2.下面是主要的xml布局的配置了

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_drawerlayout"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff00"
android:layout_marginBottom="50dp"
android:id="@+id/drawer_first"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是内容页"
/>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:id="@+id/drawer_second"
android:layout_gravity="left"
android:orientation="horizontal"
android:background="#00ffff"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是第二个页面"
/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

说重点:

侧滑的位置在哪里由这个属性决定 只有3个值:左右no

android:layout_gravity="left"

注意主界面写在三面好区分
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: