实现上拉抽屉功能

一个上拉抽屉的控件,不多说,直接看吧
首先,导入依赖

implementation 'top.iwill.mylib:slideuplayout:1.0.1'

使用说明

1、 添加布局文件

第一个儿童布局为正常布局(LinearLayout中布局1),第二个为上拉布局(的LinearLayout布局2)。正常请立即获取iTunes预览
布局2的第一个默认为上拉的控件,不能消费onTouch事件。如果需要全局拖动,设置应用:childDraggable = “真”如果上拉布局(布局2)包含一个列表视图/ recyclerview /滚动视图,需要设置childDraggable为真并在顶部的时候不消费onTouch事件,就可以衔接上滑动了。

<?xml version="1.0" encoding="utf-8"?>
<top.iwill.slideuplayout.SlideUpLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:separatePercent="50"
        app:topMargin="100dp"
        app:showHeight="120dp"
        app:childDraggable="true"
        tools:context=".MainActivity">

    <!--LinearLayout布局1-->
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    <!--LinearLayout布局2-->
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@color/colorPrimary">

        <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:src="@drawable/ic_launcher_background"
                android:layout_height="100dp"/>

        <ListView
                android:id="@+id/listview"
                android:alpha="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

    </LinearLayout>
</top.iwill.slideuplayout.SlideUpLayout>
2、属性

app:showHeight 未展开状态下布局展示高度(dimension)
app:showPercent 未展开状态下布局展示百分比(float),和showHeight一样的,不过这 个是百分比,适合在预览的时候查看全部布局
app: = topMargin 完全展开状态,上滑布局顶部距离父布局顶部的距离(dimension)
app:separatePercent 判断是该自动上滑到展开状态还是自动下滑到未展开状态的百分比。100是完全展开位置,0是未展开的默认位置。float∈[0,100]。注意如果不设置则不会自动上滑或者下滑。
app:childDraggable 是否子布局可以响应滑动(Boolean)。默认false

3.接口

interface MoveProgressListener {
        /**
         * 滑动进度监听,有可能大于1
         */
        fun onMove(progress: Float)

        /**
         * 释放时间,不再触摸
         */
        fun onRelease(child: View)

        /**
         * 滑动到顶部
         */
        fun onSlideToTop(child: View)

        /**
         * 滑动到底部
         */
        fun onSlideToBottom(child: View)
    }

Java的:
用setMoveProgressListener(listener:MoveProgressListener)进行监听注册

Kotlin(回调方法可选):

content.registerProgressListener {
            onMove {

            }
            onRelease{

            }
            onSlideToTop{

            }
            onSlideToBottom{

            }
        }

到这里就结束了,用起来很简单。可是存在一定的局限性,如果第一个布局也是需要滑动的话。可能会引起事件冲突。需要自行解决一下。

最后奉上github地址:https://github.com/btcw/SlideUpLayout

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值