Java Code Examples for androidx.core.view.ViewCompat#canScrollVertically()
The following examples show how to use
androidx.core.view.ViewCompat#canScrollVertically() .
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 toktok-android with GNU General Public License v3.0 | 6 votes |
/** * 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: ViewDragHelper.java From NewFastFrame with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: VerticalViewPager.java From DKVideoPlayer with Apache License 2.0 | 6 votes |
/** * 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 dy 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 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 (y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && canScroll(child, true, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && ViewCompat.canScrollVertically(v, -dy); }
Example 4
Source File: NestedScrollingParentView.java From zone-sdk with MIT License | 6 votes |
@Override public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { Log.e(TAG, "onNestedPreScroll"); //父控件消耗的两种情况: //1.下啦 显示头部 (里面不能下拉了,并且方向向上,并且 头部漏出) if (!ViewCompat.canScrollVertically(target, -1) && dy < 0 && getScrollY() > 0) { consumed[1] = dy; scrollBy(0, dy); } //2.上啦 隐藏头部 if (dy > 0 && getScrollY() < mTopViewHeight) { int length = mTopViewHeight - getScrollY(); consumed[1] = dy < length ? dy : length; scrollBy(0, dy); } Log.e(TAG, String.format("dx:%d \tdy:%d \tcanScrollVertically 1:%b \tcanScrollVertically -1:%b " + "自己:\tcanScrollVertically 1:%b \tcanScrollVertically -1:%b" ,dx,dy,ViewCompat.canScrollVertically(target, 1),ViewCompat.canScrollVertically(target, -1), ViewCompat.canScrollVertically(this, 1),ViewCompat.canScrollVertically(this, -1))); }
Example 5
Source File: VRefreshLayout.java From BaseProject with Apache License 2.0 | 6 votes |
private boolean isTheViewCanScrollDown(View canScrolableView) { if (canScrolableView != null) { if (android.os.Build.VERSION.SDK_INT < 14) {//android 4.0以下 if (canScrolableView instanceof AbsListView) { final AbsListView absListView = (AbsListView) canScrolableView; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) .getTop() < absListView.getPaddingTop()); } else { return ViewCompat.canScrollVertically(canScrolableView, -1) || canScrolableView.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(canScrolableView, -1); } } return false; }
Example 6
Source File: ViewDragHelper.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
/** * 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 7
Source File: ViewDragHelper.java From hipda with GNU General Public License v2.0 | 5 votes |
/** * 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 8
Source File: EasyRefreshLayout.java From DoraemonKit with Apache License 2.0 | 5 votes |
private boolean canChildScrollUp() { if (android.os.Build.VERSION.SDK_INT < 14) { if (contentView instanceof AbsListView) { final AbsListView absListView = (AbsListView) contentView; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) .getTop() < absListView.getPaddingTop()); } else { return ViewCompat.canScrollVertically(contentView, -1) || contentView.getScrollY() > 0; } } else { /*return true can swipe up*/ return ViewCompat.canScrollVertically(contentView, -1); } }
Example 9
Source File: StickyNavLayout.java From NewFastFrame with Apache License 2.0 | 5 votes |
@Override public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { Log.e(TAG, "onNestedPreScroll"); boolean hiddenTop = dy > 0 && getScrollY() < mTopViewHeight; boolean showTop = dy < 0 && getScrollY() >= 0 && !ViewCompat.canScrollVertically(target, -1); if (hiddenTop || showTop) { scrollBy(0, dy); consumed[1] = dy; } }
Example 10
Source File: ScrollChildSwipeRefreshLayout.java From simple-stack with Apache License 2.0 | 5 votes |
@Override public boolean canChildScrollUp() { if (mScrollUpChild != null) { return ViewCompat.canScrollVertically(mScrollUpChild, -1); } return super.canChildScrollUp(); }
Example 11
Source File: ScrollChildSwipeRefreshLayout.java From simple-stack with Apache License 2.0 | 5 votes |
@Override public boolean canChildScrollUp() { if(mScrollUpChild != null) { return ViewCompat.canScrollVertically(mScrollUpChild, -1); } return super.canChildScrollUp(); }
Example 12
Source File: SlidingLayout.java From CloudReader with Apache License 2.0 | 5 votes |
/** * 判断View是否可以下拉 * * @return canChildScrollDown */ public boolean canChildScrollDown() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (mTargetView instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTargetView; return absListView.getChildCount() > 0 && absListView.getAdapter() != null && (absListView.getLastVisiblePosition() < absListView.getAdapter().getCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1) .getBottom() < absListView.getPaddingBottom()); } else { return ViewCompat.canScrollVertically(mTargetView, 1) || mTargetView.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTargetView, 1); } }
Example 13
Source File: SlidingLayout.java From CloudReader with Apache License 2.0 | 5 votes |
/** * 判断View是否可以上拉 * * @return canChildScrollUp */ public boolean canChildScrollUp() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (mTargetView instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTargetView; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) .getTop() < absListView.getPaddingTop()); } else { return ViewCompat.canScrollVertically(mTargetView, -1) || mTargetView.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTargetView, -1); } }
Example 14
Source File: ViewHierarchyElementAndroid.java From Accessibility-Test-Framework-for-Android with Apache License 2.0 | 4 votes |
Builder(int id, @Nullable ViewHierarchyElementAndroid parent, View fromView) { // Bookkeeping this.id = id; this.parentId = (parent != null) ? parent.getId() : null; this.drawingOrder = null; // API 16+ properties this.scrollable = AT_16 ? fromView.isScrollContainer() : null; // API 11+ properties this.backgroundDrawableColor = (AT_11 && (fromView != null) && (fromView.getBackground() instanceof ColorDrawable)) ? ((ColorDrawable) fromView.getBackground()).getColor() : null; // Base properties this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView); this.className = fromView.getClass().getName(); this.accessibilityClassName = null; this.packageName = fromView.getContext().getPackageName(); this.resourceName = (fromView.getId() != View.NO_ID) ? ViewAccessibilityUtils.getResourceNameForView(fromView) : null; this.contentDescription = SpannableStringAndroid.valueOf(fromView.getContentDescription()); this.enabled = fromView.isEnabled(); if (fromView instanceof TextView) { TextView textView = (TextView) fromView; // Hint text takes precedence if no text is present. CharSequence text = textView.getText(); if (TextUtils.isEmpty(text)) { text = textView.getHint(); } this.text = SpannableStringAndroid.valueOf(text); this.textSize = textView.getTextSize(); this.textColor = textView.getCurrentTextColor(); this.typefaceStyle = (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null; } else { this.text = null; this.textSize = null; this.textColor = null; this.typefaceStyle = null; } this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView); this.clickable = fromView.isClickable(); this.longClickable = fromView.isLongClickable(); this.focusable = fromView.isFocusable(); this.editable = ViewAccessibilityUtils.isViewEditable(fromView); this.canScrollForward = (ViewCompat.canScrollVertically(fromView, 1) || ViewCompat.canScrollHorizontally(fromView, 1)); this.canScrollBackward = (ViewCompat.canScrollVertically(fromView, -1) || ViewCompat.canScrollHorizontally(fromView, -1)); this.checkable = (fromView instanceof Checkable); this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null; this.hasTouchDelegate = (fromView.getTouchDelegate() != null); this.touchDelegateBounds = ImmutableList.of(); // Unavailable from the View API this.boundsInScreen = getBoundsInScreen(fromView); this.nonclippedHeight = fromView.getHeight(); this.nonclippedWidth = fromView.getWidth(); this.actionList = ImmutableList.of(); // Unavailable from the View API }
Example 15
Source File: PullRefreshLayout.java From QuickDevFramework with Apache License 2.0 | 4 votes |
private boolean canChildScrollUp() { return ViewCompat.canScrollVertically(mTargetView, -1); }
Example 16
Source File: Util.java From AndroidAnimationExercise with Apache License 2.0 | 4 votes |
public static boolean canViewScrollDown(View mView, float x, float y, boolean defaultValueForNull) { if (mView == null || !contains(mView, x, y)) { return defaultValueForNull; } return ViewCompat.canScrollVertically(mView, 1); }
Example 17
Source File: Util.java From AndroidAnimationExercise with Apache License 2.0 | 4 votes |
public static boolean canViewScrollUp(View mView, float x, float y, boolean defaultValueForNull) { if (mView == null || !contains(mView, x, y)) { return defaultValueForNull; } return ViewCompat.canScrollVertically(mView, -1); }
Example 18
Source File: BottomSheetBehaviorGoogleMapsLike.java From CustomBottomSheetBehavior with Apache License 2.0 | 4 votes |
@Override public void onNestedPreScroll( CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed, @ViewCompat.NestedScrollType int type) { View scrollingChild = mNestedScrollingChildRef.get(); if ( target != scrollingChild ) { return; } mScrollVelocityTracker.recordScroll( dy ); int currentTop = child.getTop(); int newTop = currentTop - dy; // Force stop at the anchor - do not go from collapsed to expanded in one scroll if ( ( mLastStableState == STATE_COLLAPSED && newTop < mAnchorPoint ) || ( mLastStableState == STATE_EXPANDED && newTop > mAnchorPoint ) ) { consumed[1] = dy; ViewCompat.offsetTopAndBottom( child, mAnchorPoint - currentTop ); dispatchOnSlide( child.getTop() ); mNestedScrolled = true; return; } if ( dy > 0 ) { // Upward if ( newTop < mMinOffset ) { consumed[1] = currentTop - mMinOffset; ViewCompat.offsetTopAndBottom( child, -consumed[1] ); setStateInternal( STATE_EXPANDED ); } else { consumed[1] = dy; ViewCompat.offsetTopAndBottom( child, -dy ); setStateInternal( STATE_DRAGGING ); } } else if (dy < 0) { // Downward if (!ViewCompat.canScrollVertically(target, -1)) { if (newTop <= mMaxOffset || mHideable) { // Restrict STATE_COLLAPSED if restrictedState is set if(mCollapsible==true || (mCollapsible==false && (mAnchorPoint - newTop)>=0)) { consumed[1] = dy; ViewCompat.offsetTopAndBottom(child, -dy); setStateInternal(STATE_DRAGGING); } } else { consumed[1] = currentTop - mMaxOffset; ViewCompat.offsetTopAndBottom(child, -consumed[1]); setStateInternal(STATE_COLLAPSED); } } } dispatchOnSlide(child.getTop()); mNestedScrolled = true; }
Example 19
Source File: CommonSwipeRefreshLayout.java From financisto with GNU General Public License v2.0 | 4 votes |
@Override public boolean canChildScrollUp() { return mScrollingView != null && ViewCompat.canScrollVertically(mScrollingView, -1); }
Example 20
Source File: MySwipeRefreshLayout.java From DragListView with Apache License 2.0 | 4 votes |
@Override public boolean canChildScrollUp() { return mScrollingView != null && ViewCompat.canScrollVertically(mScrollingView, -1); }