🎱处理子 View,父 View 嵌套滚动,成本比 support v4 NestedScrolling 低,放心食用~
Clone or download
yangyufei
Latest commit 829006b Jan 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app upload version 1.2.1 Jan 18, 2019
captures remote demo Dec 21, 2018
gradle/wrapper init Nov 1, 2018
library upload version 1.2.1 Jan 18, 2019
.gitignore add dampen Dec 1, 2018
.project support bottomSheet Nov 28, 2018
.travis.yml add travis-ci Nov 1, 2018
LICENSE Create LICENSE Nov 2, 2018
README.md upload version 1.2.1 Jan 18, 2019
build.gradle 1.add jitpack 2.readme + usage Nov 1, 2018
gradle.properties update version Dec 1, 2018
gradlew add travis-ci Nov 1, 2018
gradlew.bat add travis-ci Nov 1, 2018
settings.gradle init Nov 1, 2018

README.md

NestedTouchScrollingLayout

Platform SDK

This layout is used to support dispatch touch event. There has some example gif~

主要用来做 View 的无缝拖拽,详细效果看 gif~


Author Jarvis
E-mail yang4130qq@gmail.com

效果

demo1 demo2
normal webview
demo3 demo4
bottomsheet normal bottomsheet appbarlayout
demo8 demo9
webview recyclerview imageview recyclerview
demo6
scene1 scene2

Usage example

normal use

<jarvis.com.library.NestedTouchScrollingLayout
    android:id="@+id/wrapper"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/container_rv"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:background="#fff"
        android:overScrollMode="always">
    </android.support.v7.widget.RecyclerView>

</jarvis.com.library.NestedTouchScrollingLayout>
// 设置手指下拉阻尼
mNestedTouchScrollingLayout.setDampingDown(2.0f / 5);
// 设置手指上拉阻尼
mNestedTouchScrollingLayout.setDampingUp(3.0f / 5);

mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
        
        // 当前 Layout 偏移距离
	@Override
	public void onNestChildScrollChange(float deltaY) {

	}
	
	// finger 脱离屏幕 Layout 偏移量,以及当前 Layout 的速度
	@Override
	public void onNestChildScrollRelease(final float deltaY, final int velocityY) {
		mNestedTouchScrollingLayout.recover(0, new Runnable() {
			@Override
			public void run() {
				Log.i("NestedTouchScrollingLayout ---> ", "deltaY : " + deltaY + " velocityY : " + velocityY);
			}
		});
	}
	// 手指抬起时机
	@Override
	public void onFingerUp(float velocityY) {

	}

	// 横向拖拽
	@Override
	public void onNestChildHorizationScroll(MotionEvent event, float deltaX, float deltaY) {
	
	}
});

bottomsheet use

 <jarvis.com.library.NestedTouchScrollingLayout
	android:id="@+id/wrapper"
	android:layout_marginTop="30dp"
	android:layout_width="match_parent"
	android:layout_height="match_parent">

	<android.support.v7.widget.RecyclerView
		android:background="#fff"
		android:id="@+id/container_rv"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />

</jarvis.com.library.NestedTouchScrollingLayout>
// 临界速度,根据业务而定
public static int mVelocityYBound = 1300;

// 规定 sheetView 弹起方向
mNestedTouchScrollingLayout.setSheetDirection(NestedTouchScrollingLayout.SheetDirection.BOTTOM);

mNestedTouchScrollingLayout.registerNestScrollChildCallback(new NestedTouchScrollingLayout.INestChildScrollChange() {
	@Override
	public void onNestChildScrollChange(float deltaY) {

	}

	@Override
	public void onNestChildScrollRelease(final float deltaY, final int velocityY) {
		int totalYRange = mNestedTouchScrollingLayout.getMeasuredHeight();
		int helfLimit = (totalYRange - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400)) / 2;
		int hideLimit = totalYRange - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400) / 2;
		int helfHeight = totalYRange - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400);
		if (velocityY > mVelocityYBound && velocityY > 0) {
			if (Math.abs(deltaY) > helfHeight) {
				mNestedTouchScrollingLayout.hiden();
			} else {
				mNestedTouchScrollingLayout.peek(mNestedTouchScrollingLayout.getMeasuredHeight() - DisplayUtils.dpToPixel(BottomSheetActivity.this,400));
			}
		} else if (velocityY < -mVelocityYBound && velocityY < 0) {
			if (Math.abs(deltaY) < helfHeight) {
				mNestedTouchScrollingLayout.expand();
			} else {
				mNestedTouchScrollingLayout.peek(mNestedTouchScrollingLayout.getMeasuredHeight() - DisplayUtils.dpToPixel(BottomSheetActivity.this,400));
			}
		} else {
			if (Math.abs(deltaY) > hideLimit) {
				mNestedTouchScrollingLayout.hiden();
			} else if (Math.abs(deltaY) > helfLimit) {
				mNestedTouchScrollingLayout.peek(mNestedTouchScrollingLayout.getMeasuredHeight() - DisplayUtils.dpToPixel(BottomSheetActivity.this, 400));
			} else {
				mNestedTouchScrollingLayout.expand();
			}
		}
	}

	@Override
	public void onFingerUp(float velocityY) {

	}

	@Override
	public void onNestChildHorizationScroll(MotionEvent event, float deltaX, float deltaY) {

	}
});

Next

  • hold all touch event, and dispath touch event to child view.
  • fix ACTION_UP dispatch child click event.
  • support bottomsheet.
  • support CoordinatorLayout (AppbarLayout).
  • add damping draging.
  • add blur cover.

Usage

方式 1:

repositories {
    // ...
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation 'com.github.JarvisGG:NestedTouchScrollingLayout:v1.2.1'
}

方式 2:

repositories {
    // ...
    jcenter()
}
dependencies {
    implementation 'com.jarvis.library.NestedTouchScrollingLayout:library:1.2.1'
}

Tip

star star star !!!!😊

LICENSE

This library is under the MIT license. check the LICENSE file for more detail.

Copyright (c) 2018 Jarvis