SlidingDrawer 就是Android的抽屉类。它的一个很明显的使用的情况是在Launcher中的效果。可以自己查看Android的源代码来。

这里就简单的说下使用方法:

首先在主布局文件里面,写入如下代码:然后再来解释为什么这样写:

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#808080"
>
<SlidingDrawer
android:id="@+id/slidingdrawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:handle="@+id/handle"
android:content="@+id/content">
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/handle"
/>
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ff00">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
/>
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#808080"
>
<SlidingDrawer
android:id="@+id/slidingdrawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:handle="@+id/handle"
android:content="@+id/content">
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/handle"
/>
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ff00">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
/>
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>

SlidingDrawer无非就是一个控件,可以在DOC中查看它的属性,说明如下:

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. 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. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use fill_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content:

这个里面我们有两个子控件,一个是handle, 一个是Content,其实也是可以重复叠加的。

然后设置handle 图标的样式,在drawable 里添加handle.xml ,代码如下:

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/handle_normal" />
<item android:state_pressed="true" android:drawable="@drawable/handle_pressed" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/handle_focused" />
<item android:state_enabled="true" android:drawable="@drawable/handle_normal" />
<item android:state_focused="true" android:drawable="@drawable/handle_focused" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/handle_normal" />
<item android:state_pressed="true" android:drawable="@drawable/handle_pressed" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/handle_focused" />
<item android:state_enabled="true" android:drawable="@drawable/handle_normal" />
<item android:state_focused="true" android:drawable="@drawable/handle_focused" />
</selector>

Android通过selector改变界面状态 ,它也就是一个资源描述文件。我们在drawable文件夹下面放了三个图片,用来描述按键的状态。
实际上这样就完成了一个Demo的操作,如果还需要更多的细节,可以参见Launcher的代码。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/dadahacker/archive/2010/07/10/5724845.aspx

更多相关文章

  1. 在android中实现手势翻页效果
  2. Android简明开发教程二十四:总结及示例代码下载
  3. 最简单的基于FFmpeg的移动端例子:Android(安卓)HelloWorld
  4. Android(安卓)webview与js 交换JSON对象数据
  5. Android(安卓)2.3姜饼的API改变大全
  6. 建立android新工程
  7. Camera服务之--架构浅析
  8. 关于Android使用proguard进行代码混淆
  9. Android应用实例之----基于Service与ContentProvider的音乐播放

随机推荐

  1. 0318作业
  2. 面向对象编程基础
  3. 如何充分利用小程序?
  4. 通过注解的 springboot+mybatis 多数据
  5. 0331作业
  6. iview的table合并相同的单元格
  7. 经济下行,程序员年底升职加薪指南
  8. 3.19作业
  9. webuploader文件上传到哪里的问题
  10. 新RabbitMQ精讲 提升工程实践能力 培养架