Java Code Examples for android.support.v7.widget.RecyclerView#computeVerticalScrollRange()

The following examples show how to use android.support.v7.widget.RecyclerView#computeVerticalScrollRange() . 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: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private void fireScrollEvent(RecyclerView recyclerView, int offsetX, int offsetY) {
  int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
  int contentHeight = recyclerView.computeVerticalScrollRange();

  Map<String, Object> event = new HashMap<>(2);
  Map<String, Object> contentSize = new HashMap<>(2);
  Map<String, Object> contentOffset = new HashMap<>(2);

  contentSize.put(Constants.Name.WIDTH, WXViewUtils.getWebPxByWidth(contentWidth, getInstance().getInstanceViewPortWidth()));
  contentSize.put(Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(contentHeight, getInstance().getInstanceViewPortWidth()));

  contentOffset.put(Constants.Name.X, - WXViewUtils.getWebPxByWidth(offsetX, getInstance().getInstanceViewPortWidth()));
  contentOffset.put(Constants.Name.Y, - WXViewUtils.getWebPxByWidth(offsetY, getInstance().getInstanceViewPortWidth()));
  event.put(Constants.Name.CONTENT_SIZE, contentSize);
  event.put(Constants.Name.CONTENT_OFFSET, contentOffset);

  fireEvent(Constants.Event.SCROLL, event);
}
 
Example 2
Source File: RecyclerViewFastScroller.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    if (scrollerView.isSelected()) return;
    int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
    int verticalScrollRange = recyclerView.computeVerticalScrollRange();
    float proportion = (float) verticalScrollOffset / ((float) verticalScrollRange - height);
    setScrollerHeight(height * proportion);
}
 
Example 3
Source File: ScrollUtils.java    From SlyceMessaging with MIT License 5 votes vote down vote up
private static int getOffsetOfGoal(int position, RecyclerView mRecyclerView, RecyclerView.Adapter mRecyclerAdapter) {
    int scrollPosition = mRecyclerView.computeVerticalScrollOffset();
    int goalPosition;
    if (position == 0) { // we are at the top
        goalPosition = 0;
    } else if (position == mRecyclerAdapter.getItemCount() - 1) {
        goalPosition = mRecyclerView.computeVerticalScrollRange();
    } else {
        goalPosition = 100000000; // this will cause scrollToPosition() to be called, which we want
    }
    return Math.abs(scrollPosition - goalPosition);
}
 
Example 4
Source File: FastScroller.java    From IPTVFree with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
    if (bubble == null || handle.isSelected())
        return;
    final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
    final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
    float proportion = (float) verticalScrollOffset / ((float) verticalScrollRange - height);
    setBubbleAndHandlePosition(height * proportion);
}
 
Example 5
Source File: RecyclerViewFastScroller.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
  if (handle.isSelected()) return;
  final int   offset      = recyclerView.computeVerticalScrollOffset();
  final int   range       = recyclerView.computeVerticalScrollRange();
  final int   extent      = recyclerView.computeVerticalScrollExtent();
  final int   offsetRange = Math.max(range - extent, 1);
  setBubbleAndHandlePosition((float) Util.clamp(offset, 0, offsetRange) / offsetRange);
}
 
Example 6
Source File: LoadMoreView.java    From PullRefreshLoadRecyclerView with MIT License 5 votes vote down vote up
private void computeOffsetWith(RecyclerView recyclerView) {
    if (recyclerView.getAdapter() == null) {
        setTranslationY(getMeasuredHeight());
        return;
    }
    int lastPosition = recyclerView.getAdapter().getItemCount() - 1;
    RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(lastPosition);
    if (viewHolder != null && viewHolder.itemView != null && viewHolder.itemView.isShown()) {
        int scrollRange = recyclerView.computeVerticalScrollRange();
        int currentScroll = recyclerView.computeVerticalScrollOffset();
        int rHeight = recyclerView.getHeight();
        int rPadTop = recyclerView.getPaddingTop();
        int offset = scrollRange - currentScroll - rHeight + getHeight() + rPadTop;

        checkAutoLoad();
        setTranslationY(offset);
        if (offset < 0) {
            dispatchOverScroll(offset, recyclerView.getScrollState());
        }
    } else if (recyclerView.getAdapter().getItemCount() == 0) {//no item
        setTranslationY(-recyclerView.getHeight() / 2 + getMeasuredHeight() / 2);
        checkAutoLoad();

    } else {
        setTranslationY(getMeasuredHeight());
    }
}
 
Example 7
Source File: Utils.java    From SimpleRecyclerView with Apache License 2.0 4 votes vote down vote up
public static boolean isScrollable(RecyclerView recyclerView) {
  return recyclerView.computeHorizontalScrollRange() > recyclerView.getWidth() ||
    recyclerView.computeVerticalScrollRange() > recyclerView.getHeight();
}
 
Example 8
Source File: GankFragment.java    From Demo_Public with MIT License 4 votes vote down vote up
private boolean isScrollToEnd(RecyclerView view){
    if (view == null) return false;
    if (view.computeVerticalScrollExtent() + view.computeVerticalScrollOffset() >= view.computeVerticalScrollRange())
        return true;
    return false;
}
 
Example 9
Source File: FastScroller.java    From APlayer with GNU General Public License v3.0 4 votes vote down vote up
private float getScrollProportion(RecyclerView recyclerView) {
  final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
  final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
  float proportion = (float) verticalScrollOffset / ((float) verticalScrollRange - mHeight);
  return mHeight * proportion;
}
 
Example 10
Source File: RecyclerViewUtil.java    From star-zone-android with Apache License 2.0 2 votes vote down vote up
/**
 * 判断recyclerview是否滑到底部
 * <p>
 * 原理:判断滑过的距离加上屏幕上的显示的区域是否比整个控件高度高
 *
 * @return
 */
public static boolean isScrollToBottom(@NonNull RecyclerView recyclerView) {
    return recyclerView != null && recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange();
}