Giter Club home page Giter Club logo

stickscrollview's Introduction

前言,一天在点外卖的时候,注意到饿了么列表页的滑动效果不错,但是觉得其中的手势滑动还是挺复杂的,正好又碰到了在熟悉Touch事件的理解当中,所以就抽空对着饿了么的列表页面尝试写写这个效果,同时增加了双列表的联动效果

APK下载地址

stickscrollview

1.先贴一个实现的效果图

image

2.引入

allprojects {
 repositories {
    jcenter()
    maven { url "https://jitpack.io" }
 }
}

dependencies {
    com.github.WelliJohn:StickScrollView:1.1.7
}

3.界面的布局说明

    <wellijohn.org.scrollviewwithstickheader.ScrollViewWithStickHeader
        android:id="@+id/stick_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/ll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:focusableInTouchMode="true"
            android:orientation="vertical">
            //这里是header部分,可以随便自定义
            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll_stick_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.design.widget.TabLayout
                    android:id="@+id/order_manager_tabs"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="#FFFFFF"
                    tools:tabGravity="fill"
                    tools:tabMode="fixed" />

                <android.support.v4.view.ViewPager
                    android:id="@+id/vp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </LinearLayout>
    </wellijohn.org.scrollviewwithstickheader.ScrollViewWithStickHeader>

比如我们看到的仿饿了么的列表页界面,我们就需要在ViewPager设置Fragment,fragment中是左右两个列表,看下fragment的xml设置:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <wellijohn.org.scrollviewwithstickheader.ChildRecyclerView
        android:id="@+id/child_recyclerview"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#EEEEEE" />

    <wellijohn.org.scrollviewwithstickheader.ChildRecyclerView//LinearLayoutManager需要继承NoSlideLinearLayoutManager,GridLayoutManager需要继承NoSlideGridLayoutManager。
        android:id="@+id/child_recyclerview_right"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:layout_weight="3" />
</LinearLayout>

4.java代码必要设置

mStickScrollView.setContentView(mLLStickList);//这个是必须的,mLLStickList就是你想到这个布局再滑动就是下面列表滑动的部分了。
mStickScrollView.setSuspensionView(mViewBottom);//这个是底部的悬浮布局,如果没有可以不设置

5.注意事项

  • ScrollViewWithStickHeader内部目前支持放置ViewPager,ScrollView,RecyclerView,WebView
  • ScrollView,RecyclerView,WebView需要对应使用ChildScrollView,ChildRecyclerView,ChildWebView
  • 我们在使用的时候,需要调用mStickScrollView.setContentView(mContentView);mLLStickList就是我们需要StickHeader+列表的部分,如果你没有StickHeader的话,那么直接设置列表进来也可以,总之,你想滑动到哪个位置接下来滑动就是单纯下面的部分滑动,那你就把下面的View整体设置为mContentView。刚刚那个的ContentView是id为ll_stick_list的View。
  • 另外在这里ScrollViewWithStickHeader增加autoscroll属性,默认是关闭的,如果autoscroll:true的话,在我们手指放开的时候,contentView会判断是否自动滑动到顶部还是隐藏不见。
  • 暂不支持weight的使用,因为weight会进行二次绘制,所以如果要实现底部bottom的话,请用RelativeiLayout
  • 如果是用RecyclerView的话,LinearLayoutManager需要继承NoSlideLinearLayoutManager,GridLayoutManager需要继承NoSlideGridLayoutManager,new NoSlideLinearLayoutManager(context)。

自动滚动的效果图

stickscrollview's People

Contributors

wellijohn avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.