Java Code Examples for android.view.View#getScrollY()

The following examples show how to use android.view.View#getScrollY() . 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: ViewDragHelper.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels along the X axis
 * @param dy Delta scrolled in pixels along the Y axis
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, dy, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) ||
            ViewCompat.canScrollVertically(v, -dy));
}
 
Example 2
Source File: ScrollController.java    From GpCollapsingToolbar with Apache License 2.0 6 votes vote down vote up
private void calculateDistance(View view, int scrollY, int oldScrollY) {
    if (mAppBarScrollRange == null || mNestedScrollRange == null) {
        return;
    }

    int totalScrollRange = mAppBarScrollRange + mNestedScrollRange;

    if (view instanceof AppBarLayout) {
        mAppBarScrollPosition = Math.abs(-scrollY);
    } else if (view instanceof NestedScrollView) {
        mNestedScrollPosition = view.getScrollY();
    }

    int scrollPosition = mAppBarScrollPosition + mNestedScrollPosition;
    mScrollPositionMultiplier = (double) (scrollPosition / totalScrollRange);
    if (mOnTotalScrollChangeListener != null) {
        mOnTotalScrollChangeListener.onTotalScrollChanged(view, scrollPosition, mOldScrollPosition, totalScrollRange);
    }
    mOldScrollPosition = scrollPosition;
}
 
Example 3
Source File: SlidingLayer.java    From android-sliding-layer-lib with Apache License 2.0 6 votes vote down vote up
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {

        if (v instanceof ViewGroup) {
            final ViewGroup group = (ViewGroup) v;
            final int scrollX = v.getScrollX();
            final int scrollY = v.getScrollY();

            final int count = group.getChildCount();
            // Count backwards - let topmost views consume scroll distance first.
            for (int i = count - 1; i >= 0; i--) {
                // TODO: Add versioned support here for transformed views.
                // This will not work for transformed views in Honeycomb+
                final View child = group.getChildAt(i);
                if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                        y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                        canScroll(child, true, dx, dy, x + scrollX - child.getLeft(),
                                y + scrollY - child.getTop())) {
                    return true;
                }
            }
        }

        return checkV && (
                (allowedDirection() == HORIZONTAL && ViewCompat.canScrollHorizontally(v, -dx) ||
                        allowedDirection() == VERTICAL && ViewCompat.canScrollVertically(v, -dy)));
    }
 
Example 4
Source File: CustomViewAbove.java    From Moring-Alarm with Apache License 2.0 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
	if (v instanceof ViewGroup) {
		final ViewGroup group = (ViewGroup) v;
		final int scrollX = v.getScrollX();
		final int scrollY = v.getScrollY();
		final int count = group.getChildCount();
		// Count backwards - let topmost views consume scroll distance first.
		for (int i = count - 1; i >= 0; i--) {
			final View child = group.getChildAt(i);
			if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
					y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
					canScroll(child, true, dx, x + scrollX - child.getLeft(),
							y + scrollY - child.getTop())) {
				return true;
			}
		}
	}

	return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}
 
Example 5
Source File: SlidingUpPanelLayout.java    From react-native-photo-editor with Apache License 2.0 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v      View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx     Delta scrolled in pixels
 * @param x      X coordinate of the active touch point
 * @param y      Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}
 
Example 6
Source File: NestedTouchScrollingLayout.java    From NestedTouchScrollingLayout with MIT License 6 votes vote down vote up
private boolean canScrollLeft(View view, float x, float y) {
    if (view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) view;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);
            int childLeft = child.getLeft() - view.getScrollX();
            int childTop = child.getTop() - view.getScrollY();
            int childRight = child.getRight() - view.getScrollX();
            int childBottom = child.getBottom() - view.getScrollY();
            boolean intersects = x > childLeft && x < childRight && y > childTop && y < childBottom;
            if (intersects && canScrollLeft(child, x - childLeft, y - childTop)) {
                return true;
            }
        }
    }
    return view.canScrollHorizontally(-1);
}
 
Example 7
Source File: SlidingUpPanelLayout.java    From AndroidSlidingUpPanel with Apache License 2.0 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v      View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx     Delta scrolled in pixels
 * @param x      X coordinate of the active touch point
 * @param y      Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }
    return checkV && v.canScrollHorizontally(-dx);
}
 
Example 8
Source File: ViewDragHelper.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels along the X axis
 * @param dy Delta scrolled in pixels along the Y axis
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, dy, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) ||
            ViewCompat.canScrollVertically(v, -dy));
}
 
Example 9
Source File: ViewDragHelper.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels along the X axis
 * @param dy Delta scrolled in pixels along the Y axis
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, dy, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) ||
            ViewCompat.canScrollVertically(v, -dy));
}
 
Example 10
Source File: ViewPager.java    From guideshow with MIT License 6 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}
 
Example 11
Source File: ViewDragHelper.java    From SwipeBack with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v      View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for
 *               scrollability (true), or just its children (false).
 * @param dx     Delta scrolled in pixels along the X axis
 * @param dy     Delta scrolled in pixels along the Y axis
 * @param x      X coordinate of the active touch point
 * @param y      Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance
        // first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft()
                    && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop()
                    && y + scrollY < child.getBottom()
                    && canScroll(child, true, dx, dy, x + scrollX - child.getLeft(), y
                    + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV
            && (v.canScrollHorizontally(-dx) || v.canScrollVertically(-dy));
}
 
Example 12
Source File: NestedTouchScrollingLayout.java    From NestedTouchScrollingLayout with MIT License 5 votes vote down vote up
/**
 * child can scroll
 * @param view
 * @param event
 * @param x
 * @param y
 * @param lockRect 是否开启 touch 所动在当前 view 区域
 * @return
 */
protected boolean canScrollDown(View view, MotionEvent event, float x, float y, boolean lockRect) {
    if (view instanceof WebView) {
        return canWebViewScrollDown((WebView) view);
    }
    if (view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) view;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);
            int childLeft = child.getLeft() - view.getScrollX();
            int childTop = child.getTop() - view.getScrollY();
            int childRight = child.getRight() - view.getScrollX();
            int childBottom = child.getBottom() - view.getScrollY();
            boolean intersects = x > childLeft && x < childRight && y > childTop && y < childBottom;
            if ((!lockRect || intersects)
                    && canScrollDown(child, event, x - childLeft, y - childTop, lockRect)) {
                return true;
            }
        }
    }

    if (view instanceof CoordinatorLayout &&
            ((CoordinatorLayout) view).getChildCount() > 0 &&
            ((CoordinatorLayout) view).getChildAt(0) instanceof AppBarLayout) {
        AppBarLayout layout = (AppBarLayout) ((CoordinatorLayout) view).getChildAt(0);
        OnNestOffsetChangedListener listener = mOnOffsetChangedListener.get(layout.hashCode());
        if (listener != null) {
            if (listener.getOffsetY() < layout.getMeasuredHeight() && listener.getOffsetY() > 0) {
                return true;
            }
        }
    }

    return isTouchUnderChildView(view, event) && view.canScrollVertically(1);
}
 
Example 13
Source File: AnimatorProxy.java    From timecat with Apache License 2.0 5 votes vote down vote up
public int getScrollY() {
    View view = mView.get();
    if (view == null) {
        return 0;
    }
    return view.getScrollY();
}
 
Example 14
Source File: ScrollingUtil.java    From TwinklingRefreshLayout with Apache License 2.0 5 votes vote down vote up
/**
 * Whether it is possible for the child view of this layout to scroll down. Override this if the child view is a custom view.
 * 判断是否可以上拉
 */
public static boolean canChildScrollDown(View mChildView) {
    if (Build.VERSION.SDK_INT < 14) {
        if (mChildView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mChildView;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else {
            return ViewCompat.canScrollVertically(mChildView, 1) || mChildView.getScrollY() < 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mChildView, 1);
    }
}
 
Example 15
Source File: AnimatorProxy.java    From imsdk-android with MIT License 5 votes vote down vote up
public int getScrollY() {
    View view = mView.get();
    if (view == null) {
        return 0;
    }
    return view.getScrollY();
}
 
Example 16
Source File: AnimatorProxy.java    From android-apps with MIT License 5 votes vote down vote up
public int getScrollY() {
    View view = mView.get();
    if (view == null) {
        return 0;
    }
    return view.getScrollY();
}
 
Example 17
Source File: HorizontalProgressHintDelegate.java    From progresshint with Apache License 2.0 4 votes vote down vote up
@Override public boolean isWidgetFullyVisible(View container) {
  int relativeTop = ViewUtil.getRelativeTop(mSeekBar, container);
  return (container.getScrollY() < relativeTop - mPopupView.getHeight() - mPopupOffset) // top edge
      && (container.getHeight() + container.getScrollY() - mPopupView.getHeight() - mPopupOffset
      > relativeTop - mSeekBar.getHeight()); // bottom edge
}
 
Example 18
Source File: ScrollProperties.java    From android_additive_animations with Apache License 2.0 4 votes vote down vote up
@Override
public Float get(View object) {
    return (float) object.getScrollY();
}
 
Example 19
Source File: WebViewDelegate.java    From ALLGO with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isReadyForPull(View view, float x, float y) {
    return view.getScrollY() <= 0;
}
 
Example 20
Source File: ScrollYDelegate.java    From KlyphMessenger with MIT License 4 votes vote down vote up
@Override
public boolean isReadyForPull(View view, float x, float y) {
    return view.getScrollY() <= 0;
}