1.xml 中的ID
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="@drawable/icon">
<!-- android:orientation="vertical" 设置抽屉 是横向还是纵向-->
<SlidingDrawer android:layout_width="fill_parent"
android:layout_height="fill_parent" android:handle="@+id/handle"
android:content="@+id/content"
android:orientation="vertical"
android:id="@+id/slidingdrawer">
<!--这里用的是 @id/handle 而不是 @+id/handle-->
<ImageButton android:id="@id/handle" android:layout_width="50dip"
android:layout_height="44dip" android:src="@drawable/icon" />
<!--这里用的是 @id/content 而不是 @+id/content-->
<LinearLayout android:id="@id/content"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#ffffff">
<!--这里的控件可以多个.-->
<TextView android:text="这是一个滑动式抽屉的示例"
android:id="@+id/tv"
android:textSize="18px"
android:textColor="#000000"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:textStyle="bold"
android:layout_height="fill_parent"></TextView>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
下面部分转自
http://www.cnblogs.com/salam/archive/2010/10/19/1855511.html
下面的链接也有关于抽屉的..
http://book.51cto.com/art/201007/212101.htm
http://wenku.baidu.com/view/9cf2952ce2bd960590c67725.html
效果图2
一、简介
SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个View组成,其一是可以拖动的handle,其二是隐藏内容的View.它里面的控件必须设置布局,在布局文件中必须指定handle和content.
例如下面
<SlidingDrawer android:layout_width="fill_parent"
android:layout_height="fill_parent" android:handle="@+id/handle"
android:content="@+id/content" android:orientation="vertical"
android:id="@+id/slidingdrawer">
<ImageButton android:id="@id/handle" android:layout_width="50dip"
android:layout_height="44dip" android:src="@drawable/up" />
<LinearLayout android:id="@id/content"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#ffffff">
<TextView android:text="这是一个滑动式抽屉的示例"
android:id="@+id/tv"
android:textSize="18px"
android:textColor="#000000"
android:gravity="center_vertical|center_horizontal"
android:layout_width="match_parent"
android:textStyle="bold"
android:layout_height="match_parent"></TextView>
</LinearLayout>
</SlidingDrawer>
二、重要属性
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。
四、完整实例
1.布局文件slidingdrawer.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="@drawable/default_bg">
<SlidingDrawer android:layout_width="fill_parent"
android:layout_height="fill_parent" android:handle="@+id/handle"
android:content="@+id/content" android:orientation="vertical"
android:id="@+id/slidingdrawer">
<ImageButton android:id="@id/handle" android:layout_width="50dip"
android:layout_height="44dip" android:src="@drawable/up" />
<LinearLayout android:id="@id/content"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#ffffff">
<TextView android:text="这是一个滑动式抽屉的示例"
android:id="@+id/tv"
android:textSize="18px"
android:textColor="#000000"
android:gravity="center_vertical|center_horizontal"
android:layout_width="match_parent"
android:textStyle="bold"
android:layout_height="match_parent"></TextView>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
2.Java代码
package com.wjq;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.SlidingDrawer;
import android.widget.TextView;
public class SlidingDrawerDemo extends Activity {
private SlidingDrawer mDrawer;
private ImageButton imbg;
private Boolean flag=false;
private TextView tv;
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sildingdrawer);
imbg=(ImageButton)findViewById(R.id.handle);
mDrawer=(SlidingDrawer)findViewById(R.id.slidingdrawer);
tv=(TextView)findViewById(R.id.tv);
mDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener()
{
@Override
public void onDrawerOpened() {
flag=true;
imbg.setImageResource(R.drawable.down);
}
});
mDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener(){
@Override
public void onDrawerClosed() {
flag=false;
imbg.setImageResource(R.drawable.up);
}
});
mDrawer.setOnDrawerScrollListener(new SlidingDrawer.OnDrawerScrollListener(){
@Override
public void onScrollEnded() {
tv.setText("结束拖动");
}
@Override
public void onScrollStarted() {
tv.setText("开始拖动");
}
});
}
}
分享到:
相关推荐
重写SlidingDrawer控件,实现向下混动的抽屉效果
SlidingDrawer抽屉式滑动效果
一个Android滑动抽屉,上滑打开,滑下来关闭,也有自动倒带。 支持正常布局,Listview,ScrollView,RecyclerView。
它可以垂直或水平滑动,它有俩个View组成,其一 是可以拖动的handle,其二是隐藏内容的View.它里面的控件必须设置布局,在布局文件中必须指定handle和content.例如下面 代码如下:<SlidingDrawer android:layout_...
抽屉效果
可拖动的滑动抽屉提供了一种从屏幕的任何一侧滑动的简便方法。 下载 只需将以下依赖项添加到build.gradle文件即可使用最新版本: dependencies { repositories { mavenCentral() } compile ' ...
SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个View组成,其一是可以拖动的handle,其二是隐藏内容的View.它里面的控件必须设置布局,在布局文件中必须指定...
最近,看到好多Android上的抽屉效果,也忍不住想要自己写一个。在Android里面可以用SlidingDrawer,很方便的实现。IOS上面就只有自己写了。其实原理很简单就是 UIView 的移动,和一些手势的操作。 效果图: // // ...
滑动抽屉 API级别17中不推荐使用android.widget.SlidingDrawer类,现在不再支持。 请参阅更多信息。 我已经在Android开放源代码项目的源代码上完成了自己的实现。 目前,它支持所有方向,即自上而下,自下而上,从左...
在Andoird使用Android自带的那些组件,像SlidingDrawer和DrawerLayout都是抽屉效果的菜单,但是在项目很多要实现的功能都收到Android这些自带组件的限制,导致很难完成项目的需求,自定义的组件,各方面都在自己的...
滑动抽屉1 这是slidingDrawer 的例子,SlidingDrawer 有handler 和context 两个方法,handle 和context 必须有唯一的id
SlidingDrawerDemo 抽屉式滑动效果
3、slidingdrawer滑动式抽屉效果实现 4、图像镜像效果,即垂直翻转效果实现。 5、从底部慢慢浮出的menu菜单效果实现。 6、preferenceScreen实现设置效果。 7、spanableString设置超链接,字体,颜色等效果实现。 ...
Adapter和AdapterView Spinner(下拉列表) ListView(列表) GridView(网格) Gallery(画廊) SlidingDrawer(滑动抽屉) AutoCompleteTextView(自动完成) TabHost(分页视图)
"SlidingDrawer抽屉效果","Android顶部与底部菜单","GroupActivity测试","Android平台水波效果源码","Android中ListView气泡显示", "桌面弹性滑动效果实现","3D相册(重写Gallery)","Activity的切换动画效果","仿...
ActivityGroup的用法,头部和底部为固定布局中间动态显示界面 并在中间布局实现手势滑动效果,自定义SlidingDrawer(抽屉)效果,在ActivityGroup里执行跳转等功能。至于在Android在ActivityGroup里执行跳转详细介绍 ...
8.8 SlidingDrawer(滑动抽屉) 8.9 Dialog(对话框) 8.9.1 AlertDialog警告框 8.9.2 ProgressDialog进度框 8.9.3 DatePickerDialog & TimePickerDialog(日期时间选择框) 8.10 Menu(菜单) 8.10.1 options menu ...