List of usage examples for android.support.v4.view ViewCompat canScrollVertically
public static boolean canScrollVertically(View v, int direction)
From source file:cn.bingoogolapple.refreshlayout.util.BGARefreshScrollingUtil.java
public static boolean isRecyclerViewToTop(RecyclerView recyclerView) { if (recyclerView != null) { RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager == null) { return true; }//w ww . jav a2 s. co m if (manager.getItemCount() == 0) { return true; } if (manager instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) manager; int firstChildTop = 0; if (recyclerView.getChildCount() > 0) { // ?item? View firstVisibleChild = recyclerView.getChildAt(0); if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) { if (android.os.Build.VERSION.SDK_INT < 14) { return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0); } else { return !ViewCompat.canScrollVertically(recyclerView, -1); } } // RecyclerView???0??top // itemtopMargin?0?? View firstChild = recyclerView.getChildAt(0); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild .getLayoutParams(); firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop(); } if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) { return true; } } else if (manager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager; int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null); if (out[0] < 1) { return true; } } } return false; }
From source file:cn.androidy.swiftlib.view.MultiSwipeRefreshLayout.java
/** * Utility method to check whether a {@link View} can scroll up from it's current position. * Handles platform version differences, providing backwards compatible functionality where * needed./*from w w w . ja v a2s .co m*/ */ private static boolean canViewScrollUp(View view) { if (android.os.Build.VERSION.SDK_INT >= 14) { // For ICS and above we can call canScrollVertically() to determine this return ViewCompat.canScrollVertically(view, -1); } else { if (view instanceof AbsListView) { // Pre-ICS we need to manually check the first visible item and the child view's top // value final AbsListView listView = (AbsListView) view; return listView.getChildCount() > 0 && (listView.getFirstVisiblePosition() > 0 || listView.getChildAt(0).getTop() < listView.getPaddingTop()); } else { // For all other view types we just check the getScrollY() value return view.getScrollY() > 0; } } }
From source file:android.support.ViewUtils.java
public static boolean canScrollUp(View view) { if (android.os.Build.VERSION.SDK_INT < 14) { if (view instanceof AbsListView) { final AbsListView absListView = (AbsListView) view; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0).getTop() < absListView.getPaddingTop()); } else {//from w w w . j ava2s. c o m return ViewCompat.canScrollVertically(view, -1) || view.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(view, -1); } }
From source file:com.czy.reecycleviewheader.ScrollableHelper.java
/** * ?,ScrollAbleLayout???//from w ww . ja va 2 s . c o m * ??AdapterView,ScrollView,RecyclerView * ??view? * * @return */ public boolean isTop() { View scrollableView = getScrollableView(); boolean isCanScrollDown = ViewCompat.canScrollVertically(scrollableView, -1); return !isCanScrollDown; // if (scrollableView == null) { //// throw new NullPointerException("You should call ScrollableHelper.setCurrentScrollableContainer() to set ScrollableContainer."); // return false; // } // if (scrollableView instanceof AdapterView) { // return isAdapterViewTop((AdapterView) scrollableView); // } // if (scrollableView instanceof ScrollView) { // return isScrollViewTop((ScrollView) scrollableView); // } // if (scrollableView instanceof RecyclerView) { // return isRecyclerViewTop((RecyclerView) scrollableView); // } // if (scrollableView instanceof WebView) { // return isWebViewTop((WebView) scrollableView); // } // throw new IllegalStateException("scrollableView must be a instance of AdapterView|ScrollView|RecyclerView"); }
From source file:com.snu_artoon.arwebtoonplayer.WebtoonView.WebtoonViewActivity.java
public static boolean isAtBottom(RecyclerView recyclerView) { return !ViewCompat.canScrollVertically(recyclerView, 1); }
From source file:com.nadmm.airports.ListFragmentBase.java
@Override public boolean canSwipeRefreshChildScrollUp() { return ViewCompat.canScrollVertically(mListView, -1); }
From source file:org.cm.podd.report.fragment.SwipeRefreshFragment.java
protected boolean canViewScrollUp(View view) { if (android.os.Build.VERSION.SDK_INT >= 14) { // For ICS and above we can call canScrollVertically() to determine this return ViewCompat.canScrollVertically(view, -1); } else {//from w w w . j a v a 2s . c o m // Pre-ICS we need to manually check the first visible item and the child view's top // value return (view.getVerticalScrollbarPosition() > 0 || view.getTop() < view.getPaddingTop()); } }
From source file:cn.zy.ef.refresh.utils.ScrollingUtil.java
public static boolean isRecyclerViewToTop(RecyclerView recyclerView) { if (recyclerView != null) { RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager == null) { return true; }/*from w w w .ja v a 2 s. c om*/ if (manager.getItemCount() == 0) { return true; } if (manager instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) manager; int firstChildTop = 0; if (recyclerView.getChildCount() > 0) { // ?item? View firstVisibleChild = recyclerView.getChildAt(0); if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) { if (Build.VERSION.SDK_INT < 14) { return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0); } else { return !ViewCompat.canScrollVertically(recyclerView, -1); } } // RecyclerView???0??top // itemtopMargin?0?? View firstChild = recyclerView.getChildAt(0); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild .getLayoutParams(); firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop(); } if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) { return true; } } else if (manager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager; int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null); if (out[0] < 1) { return true; } } } return false; }
From source file:com.lanma.customviewproject.utils.ScrollingUtil.java
/** * RecyclerView???/* w w w .jav a2 s . c om*/ */ public static boolean isRecyclerViewToTop(RecyclerView recyclerView) { if (recyclerView != null) { RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager == null) { return true; } if (manager.getItemCount() == 0) { return true; } if (manager instanceof LinearLayoutManager) { LinearLayoutManager layoutManager = (LinearLayoutManager) manager; int firstChildTop = 0; if (recyclerView.getChildCount() > 0) { // ?item? View firstVisibleChild = recyclerView.getChildAt(0); if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) { if (Build.VERSION.SDK_INT < 14) { return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0); } else { return !ViewCompat.canScrollVertically(recyclerView, -1); } } // RecyclerView???0??top // itemtopMargin?0?? View firstChild = recyclerView.getChildAt(0); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild .getLayoutParams(); firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop(); } if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) { return true; } } else if (manager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager; int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null); if (out[0] < 1) { return true; } } } return false; }
From source file:com.nadmm.airports.FragmentBase.java
@Override public boolean canSwipeRefreshChildScrollUp() { return mTopScrollView != null && ViewCompat.canScrollVertically(mTopScrollView, -1); }