android SlidingDrawer(抽屉)
16lz
2021-01-24
最近项目中用到了抽屉效果,在这儿做个备注!大家喜欢看图,我先上个图:
图中就是抽屉打开之后的效果,里面列出来了所有的正在运行的程序。点击可以关闭,点击骷髅头可以关闭所有正在运行的程序!
下面是布局文件:
注意:
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,并为其点击事件添加相应的功能代码!
下面贴一段结束应用程序的代码:
注意: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
图中就是抽屉打开之后的效果,里面列出来了所有的正在运行的程序。点击可以关闭,点击骷髅头可以关闭所有正在运行的程序!
下面是布局文件:
<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
更多相关文章
- Android使用xml自定义软键盘效果(附源码)
- Android中滑屏初探 - scrollTo 以及 scrollBy方法使用说明
- 【Android】学习笔记(6)――ListView(上)
- Material Design 方案之 (详细)
- Android中4种基本布局简单介绍和总结
- android 自定义view 前的基础知识
- Android系统开发02—Android布局管理器
- (转载)Android显示GIF
- Android(安卓)国际化笔记