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

Android Apps 滑动式抽屉(SlidingDrawer)效果

2011-12-05 13:59 471 查看
button = (Button) findViewById(R.id.button);
handle = (Button) findViewById(R.id.handle);
handle1 = (Button) findViewById(R.id.handle1);
sd = (SlidingDrawer) findViewById(R.id.slidingdrawer);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sd.animateClose();
}
});

handle1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sd.animateOpen();
}
});


下午有两个布局,实现不同的效果

===========================================================================
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="@drawable/stephy">
<Button android:id="@+id/handle1" android:layout_width="100dp" android:background="#a5f871"
android:layout_height="30dp" android:text="CLICK"/>
<SlidingDrawer android:id="@+id/slidingdrawer" android:layout_alignParentBottom="true"
android:layout_width="fill_parent" android:layout_height="130dp"
android:orientation="vertical" android:handle="@+id/handle"
android:content="@+id/content" android:bottomOffset="0px">
<Button android:id="@+id/handle" android:layout_width="100dp"
android:layout_height="30dp" android:background="#a5f871" android:text="DRAWER"/>
<LinearLayout android:id="@+id/content"
android:layout_width="fill_parent" android:layout_height="100dp" android:background="#dcf88e"
android:gravity="center_vertical|center">
<Button android:id="@+id/button" android:layout_width="wrap_content"
android:layout_height="100dp" android:text="Button" android:background="#3356e7"/>
<EditText android:id="@+id/editText" android:layout_width="fill_parent" android:layout_height="80dp"/>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>






============================================================================

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="@drawable/stephy">
<Button android:id="@+id/handle1" android:layout_width="100dp" android:background="#a5f871"
android:layout_height="30dp" android:text="CLICK"/>
<SlidingDrawer android:id="@+id/slidingdrawer" android:layout_alignParentBottom="true"
android:layout_width="fill_parent" android:layout_height="130dp"
android:orientation="vertical" android:handle="@+id/handle"
android:content="@+id/content" android:bottomOffset="0px">
<Button android:id="@+id/handle" android:layout_width="100dp"
android:layout_height="30dp" android:background="#a5f871" android:text="DRAWER"/>
<LinearLayout android:id="@+id/content"
android:layout_width="fill_parent" android:layout_height="100dp" android:background="#dcf88e"
android:gravity="center_vertical|center">
<Button android:id="@+id/button" android:layout_width="wrap_content"
android:layout_height="100dp" android:text="Button" android:background="#3356e7"/>
<EditText android:id="@+id/editText" android:layout_width="fill_parent" android:layout_height="80dp"/>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>






备注:

SlidingDrawer的属性

android:allowSingleTap:
指示是否可通过单击handle打开或关闭(如果是false,刚用户必须通过拖动,滑动或者使用轨迹球,来打开/关闭抽屉。)默认的是true。

android:animateOnClick: 指示当用户点击handle的时候,抽屉是否以动画的形式打开或关闭。默认的是true。

animateClose(): Closes
the drawer with an animation.

animateOpen(): Opens
the drawer with an animation.





备注:

SlidingDrawer的属性

android:allowSingleTap:
指示是否可通过单击handle打开或关闭(如果是false,刚用户必须通过拖动,滑动或者使用轨迹球,来打开/关闭抽屉。)默认的是true。


[b]android:animateOnClick: 指示当用户点击handle的时候,抽屉是否以动画的形式打开或关闭。默认的是true。[/b]

animateClose(): Closes
the drawer with an animation.

animateOpen(): Opens
the drawer with an animation.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: