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上玩google-breakpad(崩溃日志收集)
  2. android
  3. 了解 uri, content provide,包括 data android:host,android:schem
  4. Android中webview跟JAVASCRIPT中的交互
  5. Android中onInterceptTouchEvent与onTouchEvent
  6. -Android各版本系统源代码下载
  7. Android轻量级缓存框架ASimpleCache
  8. Android(安卓)Studio 常用快捷键
  9. 设置TextView文字居中,代码实现android:layout_gravity

随机推荐

  1. 【Android(安卓)界面效果34】Android里Se
  2. Android获得手机所有应用(非系统)、正在运
  3. Android源码学习--SystemServer进程
  4. Android(安卓)Handler机制之Handler 、Me
  5. Android各种访问权限Permission详解
  6. Android 开发工程师面试指南
  7. Android Market上发软件要注意哪些问题
  8. Android经典完美退出方法
  9. 汇编语言
  10. Android activity启动模式理解