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

The following examples show how to use android.view.View#canScrollHorizontally() . 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: AppBarLayoutUtil.java    From SmoothRefreshLayout with 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 2
Source File: ViewDragHelper.java    From Dashchan 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 && (v.canScrollHorizontally(-dx) || v.canScrollVertically(-dy));
}
 
Example 3
Source File: ViewDragHelper.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 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 4
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 5
Source File: AppBarLayoutUtil.java    From SmoothRefreshLayout with 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
Source File: CoolViewPager.java    From CoolViewPager 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--) {
            // 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 7
Source File: NestedTouchScrollingLayout.java    From NestedTouchScrollingLayout with MIT License 6 votes vote down vote up
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 8
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 9
Source File: HorizontalSmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 5 votes vote down vote up
@Override
public boolean isNotYetInEdgeCannotMoveHeader() {
    View targetView = getScrollTargetView();
    if (mInEdgeCanMoveHeaderCallBack != null) {
        return mInEdgeCanMoveHeaderCallBack.isNotYetInEdgeCannotMoveHeader(
                this, targetView, mHeaderView);
    }
    return targetView != null && targetView.canScrollHorizontally(-1);
}
 
Example 10
Source File: HorizontalSmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 5 votes vote down vote up
@Override
public boolean isNotYetInEdgeCannotMoveFooter() {
    final View targetView = getScrollTargetView();
    if (mInEdgeCanMoveFooterCallBack != null) {
        return mInEdgeCanMoveFooterCallBack.isNotYetInEdgeCannotMoveFooter(
                this, targetView, mHeaderView);
    }
    return targetView != null && targetView.canScrollHorizontally(1);
}
 
Example 11
Source File: ScrollBoundaryHorizontal.java    From SmartRefreshHorizontal with Apache License 2.0 5 votes vote down vote up
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 12
Source File: SwipeSwitchLayout.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 13
Source File: WebViewPager.java    From Rocko-Android-Demos with Apache License 2.0 5 votes vote down vote up
@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 14
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 15
Source File: TouchChildPagerLayoutManager.java    From MultiView with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: ScrollBoundaryHorizontal.java    From SmartRefreshHorizontal with Apache License 2.0 5 votes vote down vote up
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 17
Source File: al.java    From MiBandDecompiled with 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 File: ViewCompatICS.java    From letv with 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 File: FTouchHelper.java    From switchbutton with 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 File: FTouchHelper.java    From switchbutton with MIT License 2 votes vote down vote up
/**
 * view是否已经滚动到最右边
 *
 * @param view
 * @return
 */
public static boolean isScrollToRight(View view)
{
    return !view.canScrollHorizontally(1);
}