本讲内容:SlidingDrawer 抽屉类
今天我们一起学习看起来很炫、功能很强、又容易学会的抽屉类。
先用一个最简单的例子来入门。
一、实例 HelloSildingDrawer
1、新建一个项目 Lesson42_HelloSlidingDrawer
2、在Eclipse中打开main.xml,在Graphical Layout 视图里,拖拽SlidingDrawer 这个组件出来。
切换到文本方式,在SlidingDrawer标签中增加一行 android: orientation="horizontal" 给内容区添加一个背景色,以便确认,具体内容如下:
- <?xml version="1.0" encoding="utf-8"?>
- <linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
- <textview android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="欢迎进入最简单的抽屉类实例">
- <slidingdrawer android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="horizontal" android:id="@+id/slidingDrawer1" android:handle="@+id/handle" android:content="@+id/content">
- <button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/handle" android:text="Handle">
- </button>
- <linearlayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/content">
- </linearlayout>
- </slidingdrawer>
- </textview></linearlayout>
3、其他地方不需要做任何更改,直接编译运行程序,查看一下结果:
点击按钮,可以看到动画过后,拉出了一个抽屉容器:
如果我们不改方向属性的话,它默认是从下向上拉出抽屉的。二、实例:制作应用程序列表抽屉我们接下来用一个复杂点的实例,来学习SlidingDrawer的属性和方法。