android抽屉效果
2015-11-13 22:30
525 查看
所谓抽屉 是区别于侧滑菜单 他不会把内容区域挤掉 他只是覆盖在内容区域
下边一个布局文件 一个代码 可以说的就是布局文件就是
下边一个布局文件 一个代码 可以说的就是布局文件就是
<android.support.v4.widget.DrawerLayout这个布局第一个子元素是内容区 后边的是抽屉的区域 抽屉的layout_gravity属性是自己手写的编译器不会自动提示 属性 start left为布局放在左边 end right为布局放在右边 侧滑就可以出来 不用响应事件 当然也可以让其响应事件 打开抽屉的方法为 mDrawerLayout.openDrawer(Gravity.LEFT); 通过里边的参数来指定哪个抽屉划出
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".DrawerActivity" > <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="open" /> </FrameLayout> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#111" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> </RelativeLayout>
package com.example.hellodrawer; import android.os.Bundle; import android.app.Activity; import android.support.v4.widget.DrawerLayout; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class DrawerActivity extends Activity { private DrawerLayout mDrawerLayout = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Button button = (Button) findViewById(R.id.btn); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 按钮按下,将抽屉打开 mDrawerLayout.openDrawer(Gravity.LEFT); } }); } }
相关文章推荐
- Android新特性v7 - CardView
- android事件总线 otto使用
- Android打包签名(Keytool)
- Android自定义控件之日历控件
- android studio gradle更新错误
- Android Studio -修改LogCat的颜色*美爆了*
- Android Studio断点调试图文详解(超简单,一看就会)
- Android Studio断点调试图文详解(超简单,一看就会)
- Android源码阅读与理解(一):开篇
- 【Android】Android项目中R文件找不到怎么处理?
- android收集
- Android短信的发送与接收
- Android开发岗位要求集锦
- Android新特性-RecyclerView之基础篇
- 【Android】点击事件的几种方法
- android 解决listview 内部有按键控件时,listview无法点击
- Android:View中的performClick()触发条件
- Android:dimen尺寸资源文件的使用
- 如何不翻墙下载Android源代码
- Android Studio开发工具快捷键