最近项目中用到了抽屉效果,在这儿做个备注!大家喜欢看图,我先上个图:


图中就是抽屉打开之后的效果,里面列出来了所有的正在运行的程序。点击可以关闭,点击骷髅头可以关闭所有正在运行的程序!
下面是布局文件:

    <SlidingDrawer        android:id="@+id/run_app"        android:layout_width="555dip"        android:layout_height="56dip"                android:layout_gravity="right|center"        android:layout_marginTop="00dip"                android:orientation="horizontal"                android:handle="@+id/handle"        android:content="@+id/all_run_app">        <ImageView        android:id="@+id/handle"         android:src="@drawable/death"        android:layout_width="wrap_content"        android:layout_height="56dip"        /><LinearLayout        android:id="@+id/all_run_app"    android:orientation="horizontal"        android:background="#00000000" android:layout_width="wrap_content"android:layout_height="wrap_content"><LinearLayout    android:orientation="vertical"android:layout_width="wrap_content"android:layout_height="56dip"        android:background="@drawable/rounded_kill_img" ><LinearLayout    android:orientation="horizontal"android:layout_width="wrap_content"android:layout_height="38dip">        <ImageView         android:id="@+id/refresh_all"        android:src="@drawable/refresh_press"        android:layout_width="wrap_content"        android:layout_height="38dip"/>        <ImageView         android:id="@+id/kill_all"        android:src="@drawable/kill_all_press"        android:layout_width="wrap_content"        android:layout_height="38dip"/>        </LinearLayout>        <TextView         android:id="@+id/show_mem"        android:layout_width="wrap_content"        android:layout_height="18dip"        android:textSize="12dip"/>        </LinearLayout>                <GridView         android:id="@+id/grid_all"        android:numColumns="12"        android:background="@drawable/rounded_kill_img"         android:layout_width="wrap_content"        android:layout_height="wrap_content"/>        </LinearLayout>    </SlidingDrawer>

注意:
1、如果给SlidingDrawer添加android:clickable="true"则在抽屉活动的一块区域屏幕不会响应其他点击事件,即使抽屉式关闭的。
2、android:handle="@+id/handle"里面的handle是SlidingDrawer标签里面你要作为抽屉图标的view的id。android:content="@+id/all_run_app"中的all_run_app是SlidingDrawer标签里面你要作为抽屉里面内容显示的view布局的id。
3、上面的android:background="@drawable/rounded_kill_img"这句就是指定图中的圆角半透明背景的布局文件,我博客之前的一片文章有介绍这个!
4、android:numColumns="12"是指定GridView中一行所显示的数量。
其他就是在代码中初始化每个view,并为其点击事件添加相应的功能代码!

下面贴一段结束应用程序的代码:
private List<String> processName = new ArrayList<String>();ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);for (String pName : processName) {manager.restartPackage(pName);}

注意:restartPackage(pName);这个方法在2.1上可以结束一切应用程序,但在2.2上只能结束部分程序。关于结束本进程以及其他程序或进程大家可以参考这儿:http://www.cnblogs.com/crazypebble/archive/2011/04/05/2006213.html
http://h3clikejava.blog.163.com/blog/static/134473029201112083447207/

如果抽屉下方的布局是listview等,在使用了LinearLayout时抽屉是不会显示在这些view的上面的。为什么呢?
参考了这儿:
http://www.eoeandroid.com/forum-viewthread-tid-62987-highlight-SlidingDrawer.html
将最外层的布局形式改成了FrameLayout ,问题是解决了。
官方文档上是这么说:
SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance

更多相关文章

  1. Android使用xml自定义软键盘效果(附源码)
  2. Android中滑屏初探 - scrollTo 以及 scrollBy方法使用说明
  3. 【Android】学习笔记(6)――ListView(上)
  4. Material Design 方案之 (详细)
  5. Android中4种基本布局简单介绍和总结
  6. android 自定义view 前的基础知识
  7. Android系统开发02—Android布局管理器
  8. (转载)Android显示GIF
  9. Android(安卓)国际化笔记

随机推荐

  1. Android Zxing修改二维码中扫描框的大小
  2. android 程序框架--资源和资产
  3. mac 下配置ANDROID_HOME环境变量
  4. android退出程序 后台运行 实现退出键和h
  5. Android运行时异常“Binary XML file lin
  6. android中在切换fragment时,怎样做到无需
  7. android 开发常用代码备查[更新20150520]
  8. http://www.jb51.net/article/37855.htm
  9. android创建Popwindow弹出菜单的两种方式
  10. Android自定义Dialog的Match_parent无效