转载注明出处:http://blog.csdn.net/forwardyzk/article/details/42557355
系统自带的SlidingDrawer,只提供了两个方向的滑动:从下到上,从右到左。下面介绍四个方向都可以滑动的抽屉控件。
自定义控件,包含自定义属性,可以制定方向。leftToRight,bottomToTop,rightToLeft,topToBottom
handle.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:gravity="center"
android:padding="10dp"
android:text="拉手"
android:textColor="@color/handle"
android:textSize="30sp" />
</RelativeLayout>
content.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/content"
android:gravity="center"
android:text="抽屉内容"
android:textColor="@android:color/black" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/com.example.demoslidingdrawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
my:content="@+id/content"
my:direction="topToBottom"
my:handle="@+id/handle" >
<include
android:id="@id/content"
layout="@layout/content" />
<include
android:id="@id/handle"
layout="@layout/handle" />
</com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer>
<com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/com.example.demoslidingdrawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
my:content="@+id/content"
my:direction="rightToLeft"
my:handle="@+id/handle" >
<include
android:id="@id/content"
layout="@layout/content" />
<include
android:id="@id/handle"
layout="@layout/handle" />
</com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer>
<com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/com.example.demoslidingdrawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
my:content="@+id/content"
my:direction="bottomToTop"
my:handle="@+id/handle" >
<include
android:id="@id/content"
layout="@layout/content" />
<include
android:id="@id/handle"
layout="@layout/handle" />
</com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer>
<com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/com.example.demoslidingdrawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
my:content="@+id/content"
my:direction="leftToRight"
my:handle="@+id/handle" >
<include
android:id="@id/content"
layout="@layout/content" />
<include
android:id="@id/handle"
layout="@layout/handle" />
</com.example.demoslidingdrawer.view.MultiDirectionSlidingDrawer>
</RelativeLayout>
自定义属性控件,请参考:http://blog.csdn.net/forwardyzk/article/details/25079743
源码下载:http://download.csdn.net/detail/forwardyzk/8345333效果图: