仿QQ侧滑效果,DragLayout使用方法

    最近公司的项目要实现一个类似Android版QQ的侧滑功能。查找了一下相关的资料发现GitHub上已经有类似的效果了,比较火的有ResideMenu和DragLayout,DragLayout相对来说简单不少,实现起来非常方便。GitHub地址:https://github.com/BlueMor/DragLayout。

  要使用DragLayout只要把DragLayout和MyRelativeLayout这两个类复制到自己的项目中,在定义xml文件的时候将主界面和需要侧滑出的界面写在一起就行, 这里要注意最外层的Layout需要设为DragLayout:

 <com.xxx.DragLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dragLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</com.xxx.DragLayout>

  主界面的Layout需要用 MyRelativeLayout包裹,顾名思义这里的MyRelativeLayout继承的是RelativeLayout,如果需要使用LinearLayout可以自行嵌套。

  完整xml:

 

<yourpackagename.DragLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dragLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 <LinearLayout
            android:id="@+id/lin_mytime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/lin_avatar"
            android:layout_marginLeft="32dp"
            android:layout_marginTop="60dp"
            android:orientation="horizontal" >


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:src="@drawable/background" />


            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:background="@color/transparent"/>
        </LinearLayout>
 <yourpackagename.MyRelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background" >

        <include
            android:id="@+id/topbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/topbar_height"
            layout="@layout/main_topbar" />

        <GridView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/topbar"
            android:background="@drawable/background"
            android:gravity="center"
            android:numColumns="2"
            android:stretchMode="columnWidth" >
        </GridView>
    </yourpackagename.MyRelativeLayout>
</yourpackagename.DragLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值