自定义抽屉

转载注明出处: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>


main.xml

<?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
效果图:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值