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

The following examples show how to use android.view.View#canScrollHorizontally() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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 2
private boolean canScrollRight(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 && canScrollRight(child, x - childLeft, y - childTop)) {
                return true;
            }
        }
    }
    return view.canScrollHorizontally(1);
}
 
Example 3
Source Project: CoolViewPager   File: CoolViewPager.java    License: 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--) {
            // 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 && v.canScrollHorizontally(-dx);
}
 
Example 4
Source Project: SmoothRefreshLayout   File: AppBarLayoutUtil.java    License: MIT License 6 votes vote down vote up
@Override
public boolean isNotYetInEdgeCannotMoveHeader(
        SmoothRefreshLayout parent, @Nullable View child, @Nullable IRefreshView header) {
    if (child == null) {
        if (parent.isVerticalOrientation()) {
            return !mFullyExpanded;
        } else {
            return true;
        }
    } else {
        if (parent.isVerticalOrientation()) {
            return !mFullyExpanded || child.canScrollVertically(-1);
        } else {
            return child.canScrollHorizontally(-1);
        }
    }
}
 
Example 5
Source Project: SmoothRefreshLayout   File: AppBarLayoutUtil.java    License: MIT License 6 votes vote down vote up
@Override
public boolean isNotYetInEdgeCannotMoveFooter(
        SmoothRefreshLayout parent, @Nullable View child, @Nullable IRefreshView footer) {
    if (child == null) {
        if (parent.isVerticalOrientation()) {
            return !mFullyCollapsed;
        } else {
            return true;
        }
    } else {
        if (parent.isVerticalOrientation()) {
            return !mFullyCollapsed || child.canScrollVertically(1);
        } else {
            return child.canScrollHorizontally(1);
        }
    }
}
 
Example 6
/**
 * 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 7
/**
 * 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 8
Source Project: Dashchan   File: ViewDragHelper.java    License: 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 && (v.canScrollHorizontally(-dx) || v.canScrollVertically(-dy));
}
 
Example 9
public static boolean canScrollLeft(@NonNull View targetView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (targetView instanceof AbsListView) {
            final ViewGroup viewGroup = (ViewGroup) targetView;
            final AbsListView absListView = (AbsListView) targetView;
            return viewGroup.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0
                    || viewGroup.getChildAt(0).getTop() < targetView.getPaddingTop());
        } else {
            return targetView.getScrollY() > 0;
        }
    } else {
        return targetView.canScrollHorizontally(-1);
    }
}
 
Example 10
public static boolean canScrollRight(@NonNull View targetView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (targetView instanceof AbsListView) {
            final ViewGroup viewGroup = (ViewGroup) targetView;
            final AbsListView absListView = (AbsListView) targetView;
            final int childCount = viewGroup.getChildCount();
            return childCount > 0 && (absListView.getLastVisiblePosition() < childCount - 1
                    || viewGroup.getChildAt(childCount - 1).getBottom() > targetView.getPaddingBottom());
        } else {
            return targetView.getScrollY() < 0;
        }
    } else {
        return targetView.canScrollHorizontally(1);
    }
}
 
Example 11
@Override
public boolean isNotYetInEdgeCannotMoveHeader() {
    View targetView = getScrollTargetView();
    if (mInEdgeCanMoveHeaderCallBack != null) {
        return mInEdgeCanMoveHeaderCallBack.isNotYetInEdgeCannotMoveHeader(
                this, targetView, mHeaderView);
    }
    return targetView != null && targetView.canScrollHorizontally(-1);
}
 
Example 12
@Override
public boolean isNotYetInEdgeCannotMoveFooter() {
    final View targetView = getScrollTargetView();
    if (mInEdgeCanMoveFooterCallBack != null) {
        return mInEdgeCanMoveFooterCallBack.isNotYetInEdgeCannotMoveFooter(
                this, targetView, mHeaderView);
    }
    return targetView != null && targetView.canScrollHorizontally(1);
}
 
Example 13
@Override
public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int axes, int type) {
    isBeingNestedScrolling = true;
    if ((!target.canScrollHorizontally(-1) && !target.canScrollHorizontally(1))
            || swipeDistance != 0) {
        nestedScrollingDistance = nestedScrollingTrigger;
    } else {
        nestedScrollingDistance = 0;
    }
}
 
Example 14
@Override
		protected boolean canScroll(View webView, boolean checkV, int dx, int x, int y) {
			if (webView instanceof HorizontalSlideWebView) {
//			Log.d(TAG, "dx: " + dx + " x:" + x + " y:" + y);
				return webView.canScrollHorizontally(y); // 不再兼容 API < 14
			} else {
				return super.canScroll(webView, checkV, dx, x, y);
			}
		}
 
Example 15
/**
 * 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 16
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
    final int layoutDirection = dx > 0 ? 1 : -1;
    View currView = getCurrentPageView();
    //check if we need to work with the child view
    if (recyclerView != null && currView != null && currView.canScrollHorizontally(layoutDirection)
            && ((layoutDirection == 1 && currView.getLeft() <= 0) ||
            (layoutDirection == -1 && currView.getRight() >= currView.getWidth()))
            ) {
        dOffset = 0;
        if (lastTouchEvent != null) {
            currView.dispatchTouchEvent(lastTouchEvent);
            lastTouchEvent = null;
        }
        ViewCompat.setOverScrollMode(recyclerView, ViewCompat.OVER_SCROLL_NEVER);

        if ((layoutDirection == 1 && currView.getLeft() < 0) || (layoutDirection == -1 && currView.getRight() > currView.getWidth())) {
            adjust();
        }
        return 0;
    } else if (Math.abs(dOffset + dx) < triggPx &&
            recyclerView != null && currView != null &&
            currView.getLeft() == 0 && currView.getRight() == currView.getWidth()
            ) {
        dOffset += dx;
        if (lastTouchEvent != null) {
            currView.dispatchTouchEvent(lastTouchEvent);
            lastTouchEvent = null;
        }
        ViewCompat.setOverScrollMode(recyclerView, ViewCompat.OVER_SCROLL_NEVER);
        return 0;
    } else {
        dOffset = 0;
        ViewCompat.setOverScrollMode(recyclerView, ViewCompat.OVER_SCROLL_ALWAYS);
        return super.scrollHorizontallyBy(dx, recycler, state);
    }
}
 
Example 17
Source Project: MiBandDecompiled   File: al.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean a(View view, int i)
{
    return view.canScrollHorizontally(i);
}
 
Example 18
Source Project: letv   File: ViewCompatICS.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean canScrollHorizontally(View v, int direction) {
    return v.canScrollHorizontally(direction);
}
 
Example 19
Source Project: switchbutton   File: FTouchHelper.java    License: MIT License 2 votes vote down vote up
/**
 * view是否已经滚动到最左边
 *
 * @param view
 * @return
 */
public static boolean isScrollToLeft(View view)
{
    return !view.canScrollHorizontally(-1);
}
 
Example 20
Source Project: switchbutton   File: FTouchHelper.java    License: MIT License 2 votes vote down vote up
/**
 * view是否已经滚动到最右边
 *
 * @param view
 * @return
 */
public static boolean isScrollToRight(View view)
{
    return !view.canScrollHorizontally(1);
}