VerticalSlideView

Introduction: 类似淘宝的商品详情页,继续拖动查看详情,其中拖动增加了阻尼,并且重写了 ListView,GridView,ScrollView,WebView,RecyclerView 的 dispatchTouchEvent 方法,使用的时候无须额外的代码,可以任意嵌套使用。
More: Author   ReportBugs   
Tags:

类似淘宝的商品详情页,继续拖动查看详情,其中拖动增加了阻尼,并且重写了 ListView,GridView,ScrollView,WebView,RecyclerView 的 dispatchTouchEvent 方法,使用的时候无须额外的代码,可以任意嵌套使用。

该项目参考了:https://github.com/xmuSistone/android-vertical-slide-view 喜欢原作的可以去使用。相比原项目,代码更简单易懂,扩展性更高,欢迎大家下载体验本项目,如果使用过程中遇到什么问题,欢迎反馈。

联系方式

  • 邮箱地址: liaojeason@126.com
  • QQ 群: 489873144 (建议使用 QQ 群,邮箱使用较少,可能看的不及时)
  • 本群刚建立,旨在为使用我的 github 项目的人提供方便,如果遇到问题欢迎在群里提问。个人能力也有限,希望一起学习一起进步。

演示

imageimageimageimage

1.用法

该项目和我 github 上其他的 view 相关的项目已经一起打包上传到 jCenter 仓库中(源码地址 https://github.com/jeasonlzy0216/ViewCore ),使用的时候可以直接使用 compile 依赖,用法如下

    compile 'com.lzy.widget:view-core:0.2.3'

或者使用

    compile project(':verticalslide')

2.实现原理

把 ListView,GridView,ScrollView,WebView,RecyclerView 的 dispatchTouchEvent 方法进行重写,当这几个 View 在对顶部并且向下拉 或者 在对底部向上拉时,自身不消费事件,让父容器拦截事件并处理。并支持 ViewPager。

3.代码参考

1.对于加载下一页的监听,只需要初始化控件并且设置监听即可

    DragSlideLayout dragLayout = (DragSlideLayout) findViewById(R.id.dragLayout);
    dragLayout.setOnShowNextPageListener(new DragSlideLayout.OnShowNextPageListener() {
        @Override
        public void onShowNextPage() {
            fragment_webView.initView();
        }
    });

2.支持快速返回第一页

    @Override
    public void onClick(View v) {
        /**
         * 返回顶部分三步
         * 1.第二页滚动到第二页的顶部
         * 2.VerticalSlide 从第二页返回第一页
         * 3.第一页滚动到第一页的顶部
         * OnGoTopListener 表示第一页滚动到顶部 的方法,这个由于采用什么布局,库内部并不知道,所以一般是自己实现
         * 也可以不实现,直接传 null
         */
        bottomFragment.goTop();
        verticalSlide.goTop(new VerticalSlide.OnGoTopListener() {
            @Override
            public void goTop() {
                topFragment.goTop();
            }
        });
    }

3.使用DragSlideLayout控件,内部包含两个子 View,分别表示第一页和第二页,可以先使用FrameLayout占位,代码中使用 Fragment 替换

    <?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">

        <com.lzy.ui.DragSlideLayout
            android:id="@+id/dragLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <FrameLayout
                android:id="@+id/first"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <FrameLayout
                android:id="@+id/second"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
        </com.lzy.ui.DragSlideLayout>
    </RelativeLayout>

4.也可以直接使用VerticalScrollView,或者VerticalListView,等替换,上下两个布局可以任意调换

    <?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">

        <com.lzy.ui.DragSlideLayout
            android:id="@+id/dragLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.lzy.ui.VerticalScrollView
                android:id="@+id/custScrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#fff"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    ......

                </LinearLayout>

            </com.lzy.ui.VerticalScrollView>

            <com.lzy.ui.VerticalListView
                android:id="@+id/listView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />

        </com.lzy.ui.DragSlideLayout>
    </RelativeLayout>
Apps
About Me
GitHub: Trinea
Facebook: Dev Tools