Java Code Examples for android.support.v4.view.ViewCompat#NestedScrollType
The following examples show how to use
android.support.v4.view.ViewCompat#NestedScrollType .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NestedChildHelper.java From customview-samples with Apache License 2.0 | 5 votes |
/** * Stop a nested scroll in progress. * * <p>This is a delegate method. Call it from your {@link android.view.View View} subclass * method/{@link android.support.v4.view.NestedScrollingChild2} interface method with the same * signature to implement the standard policy.</p> */ public void stopNestedScroll(@ViewCompat.NestedScrollType int type) { ViewParent parent = getNestedScrollingParentForType(type); if (parent != null) { ViewParentCompat.onStopNestedScroll(parent, mView, type); setNestedScrollingParentForType(type, null); } }
Example 2
Source File: NestedChildHelper.java From customview-samples with Apache License 2.0 | 5 votes |
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable int[] offsetInWindow, @ViewCompat.NestedScrollType int type) { if (isNestedScrollingEnabled()) { //获取实现了NestedScrollingParent2或NestedScrollingParent的祖辈控件,如果没有则为null final ViewParent parent = getNestedScrollingParentForType(type); if (parent == null) { //没有实现NestedScrollingParent2或NestedScrollingParent的祖辈控件,则不作任何处理 return false; } if (dxConsumed != 0 || dyConsumed != 0 || dxUnconsumed != 0 || dyUnconsumed != 0) { int startX = 0; int startY = 0; if (offsetInWindow != null) { mView.getLocationInWindow(offsetInWindow); startX = offsetInWindow[0]; startY = offsetInWindow[1]; } //将嵌套滑动事件分发给祖辈控件的onNestedScroll方法 ViewParentCompat.onNestedScroll(parent, mView, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type); if (offsetInWindow != null) { mView.getLocationInWindow(offsetInWindow); offsetInWindow[0] -= startX; offsetInWindow[1] -= startY; } return true; } else if (offsetInWindow != null) { // No motion, no dispatch. Keep offsetInWindow up to date. offsetInWindow[0] = 0; offsetInWindow[1] = 0; } } return false; }
Example 3
Source File: NestedChildHelper.java From customview-samples with Apache License 2.0 | 5 votes |
private ViewParent getNestedScrollingParentForType(@ViewCompat.NestedScrollType int type) { switch (type) { case TYPE_TOUCH: return mNestedScrollingParentTouch; case TYPE_NON_TOUCH: return mNestedScrollingParentNonTouch; } return null; }
Example 4
Source File: NestedChildHelper.java From customview-samples with Apache License 2.0 | 5 votes |
private void setNestedScrollingParentForType(@ViewCompat.NestedScrollType int type, ViewParent p) { switch (type) { case TYPE_TOUCH: mNestedScrollingParentTouch = p; break; case TYPE_NON_TOUCH: mNestedScrollingParentNonTouch = p; break; } }
Example 5
Source File: NestedChildHelper.java From customview-samples with Apache License 2.0 | 4 votes |
public boolean dispatchNestedPreScroll(int dx, int dy, @Nullable int[] consumed, @Nullable int[] offsetInWindow, @ViewCompat.NestedScrollType int type) { if (isNestedScrollingEnabled()) { //获取实现了NestedScrollingParent2或NestedScrollingParent的祖辈控件,如果没有则为null final ViewParent parent = getNestedScrollingParentForType(type); if (parent == null) { //没有实现NestedScrollingParent2或NestedScrollingParent的祖辈控件,则不作任何处理 return false; } if (dx != 0 || dy != 0) { int startX = 0; int startY = 0; if (offsetInWindow != null) { mView.getLocationInWindow(offsetInWindow); startX = offsetInWindow[0]; startY = offsetInWindow[1]; } if (consumed == null) { if (mTempNestedScrollConsumed == null) { mTempNestedScrollConsumed = new int[2]; } consumed = mTempNestedScrollConsumed; } consumed[0] = 0; consumed[1] = 0; //将嵌套滑动事件分发给祖辈控件的onNestedPreScroll方法 ViewParentCompat.onNestedPreScroll(parent, mView, dx, dy, consumed, type); if (offsetInWindow != null) { mView.getLocationInWindow(offsetInWindow); offsetInWindow[0] -= startX; offsetInWindow[1] -= startY; } return consumed[0] != 0 || consumed[1] != 0; } else if (offsetInWindow != null) { offsetInWindow[0] = 0; offsetInWindow[1] = 0; } } return false; }
Example 6
Source File: NestedChildHelper.java From customview-samples with Apache License 2.0 | 2 votes |
/** * Check if this view has a nested scrolling parent view currently receiving events for * a nested scroll in progress with the given type. * * <p>This is a delegate method. Call it from your {@link android.view.View View} subclass * method/{@link android.support.v4.view.NestedScrollingChild} interface method with the same * signature to implement the standard policy.</p> * * @return true if this view has a nested scrolling parent, false otherwise */ public boolean hasNestedScrollingParent(@ViewCompat.NestedScrollType int type) { return getNestedScrollingParentForType(type) != null; }
Example 7
Source File: HeaderBehavior.java From CoordinatorLayoutExample with Apache License 2.0 | 2 votes |
/** * when scrooll, it would call back * * @param isUp isScroollUp * @param dy child.getTanslationY * @param type touch or not touch, TYPE_TOUCH, TYPE_NON_TOUCH */ void onScrollChange(boolean isUp, int dy, @ViewCompat.NestedScrollType int type);
Example 8
Source File: GroupHeaderBehavior.java From CoordinatorLayoutExample with Apache License 2.0 | 2 votes |
/** * when scrooll, it would call back * * @param isUp * @param dy child.getTanslationY * @param type */ void onScrollChange(boolean isUp, int dy, @ViewCompat.NestedScrollType int type);