您的位置:首页 > 移动开发 > Android开发

Android SlidingDrawer(滑动式抽屉)

2015-10-23 19:57 465 查看
先上效果图:





该控件用法简单,如果自己加以美化,定能做出很炫的想要的效果

一、SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个View组成,其一是可以拖动的handle,其二是隐藏内容的View.它里面的控件必须设置布局,在布局文件中必须指定handle和content.

二、重要属性

  android:allowSingleTap:指示是否可以通过handle打开或关闭

  android:animateOnClick:指示是否当使用者按下手柄打开/关闭时是否该有一个动画。

  android:content:隐藏的内容

  android:handle:handle(手柄)

三、重要方法

  animateClose():关闭时实现动画。

  close():即时关闭

  getContent():获取内容

  isMoving():指示SlidingDrawer是否在移动。

  isOpened():指示SlidingDrawer是否已全部打开

  lock():屏蔽触摸事件。

  setOnDrawerCloseListener(SlidingDrawer.OnDrawerCloseListener onDrawerCloseListener):SlidingDrawer关闭时调用

  unlock():解除屏蔽触摸事件。

  toggle():切换打开和关闭的抽屉SlidingDrawer。

四、完整实例

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >

<SlidingDrawer
android:orientation="horizontal"
android:id="@+id/sl"
android:content="@+id/tex"
android:handle="@+id/but"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_world" >

<ImageView
android:id="@id/tex"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
/>

<Button
android:text="打开"
android:id="@id/but"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</Button>
</SlidingDrawer>

</RelativeLayout>


主Activity

package com.example.slidingdrawer;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SlidingDrawer;

public class MainActivity extends Activity {
SlidingDrawer slidingDrawer ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}


简单的用法就大概这样,至于要用到别的,自行增添。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: