【Android】抽屉控件 SlidingDrawer 的简单示例
【Android】抽屉控件 SlidingDrawer 的简单示例
【0】先看一段官方描述:public class
SlidingDrawer
extends ViewGroupjava.lang.Object | |||
↳ | Android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.widget.SlidingDrawer |
Class Overview
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 match_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content:
- <SlidingDrawer
- android:id="@+id/drawer"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:handle="@+id/handle"
- android:content="@+id/content">
- <ImageView
- android:id="@id/handle"
- android:layout_width="88dip"
- android:layout_height="44dip" />
- <GridView
- android:id="@id/content"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </SlidingDrawer>
【1】简单的说就是:
SlidingDrawer是一个可以实现抽取式显示的控件,可以垂直,水平拉取,每个抽屉都包含两个东西:一个是拉手(handle),一个是抽屉里面的东西(content),SlidingDrawer需要放置在另外的一个layout之上,这意味着SlidingDrawer只能放置在 FrameLayout or a RelativeLayout里面。SlidingDrawer需要设置宽高为match_parent,而且在SlidingDrawer里面必须设置handle与content(显然,不然缺少任何一个都不叫“抽屉”啊)
【2】一些重要的属性与方法:
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:allowSingleTap | Indicates whether the drawer can be opened/closed by a single tap on the handle. 指示是否可以通过handle打开或关闭 | ||||||||||
android:animateOnClick | Indicates whether the drawer should be opened/closed with an animation when the user clicks the handle. 指示是否当使用者按下手柄打开/关闭时是否该有一个动画 | ||||||||||
android:bottomOffset | Extra offset for the handle at the bottom of the SlidingDrawer. | ||||||||||
android:content | Identifier for the child that represents the drawer's content.指定抽屉的内容 | ||||||||||
android:handle | Identifier for the child that represents the drawer's handle.指定把手handle | ||||||||||
android:orientation | Orientation of the SlidingDrawer. 水平还是垂直 | ||||||||||
android:topOffset | Extra offset for the handle at the top of the SlidingDrawer. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
【4】Demo演示:
[html]- <?xml version="1.0" encoding="utf-8"?>
- <merge
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <ImageView
- android:id="@+id/OrginView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/orginview"
- android:contentDescription="@string/image_org"/>
- <SlidingDrawer
- android:id="@+id/SlidingDrawer"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:handle="@+id/handle"
- android:content="@+id/content" >
- <ImageView
- android:id="@id/handle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/handleview"
- android:contentDescription="@string/image_handle" />
- <ImageView
- android:id="@id/content"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/contentview"
- android:contentDescription="@string/image_content" />
- </SlidingDrawer>
- </merge>
这里使用到了<merge>标签,详细使用方法请看;http://developer.android.com/resources/articles/layout-tricks-merge.html
|
评论暂时关闭