Java Code Examples for android.support.v7.widget.LinearLayoutManager#getReverseLayout()

The following examples show how to use android.support.v7.widget.LinearLayoutManager#getReverseLayout() . 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: PullRefreshLoadRecyclerView.java    From PullRefreshLoadRecyclerView with MIT License 6 votes vote down vote up
@Override
public void setLayoutManager(LayoutManager layout) {
    if (layout != null && !(layout instanceof OverScrollImpl.OverScrollLayoutManager)) {
        if (layout.getClass().equals(GridLayoutManager.class)) {
            GridLayoutManager grid = (GridLayoutManager) layout;
            layout = new OverScrollGridManager(this, grid.getSpanCount(), grid.getOrientation(), grid.getReverseLayout());
        } else if (layout.getClass().equals(LinearLayoutManager.class)) {
            LinearLayoutManager linear = (LinearLayoutManager) layout;
            layout = new OverScrollLinearLayoutManager(this, linear.getOrientation(), linear.getReverseLayout());
        } else {
            throw new IllegalArgumentException("LayoutManager " + layout +
                    " should be subclass of: " + OverScrollLinearLayoutManager.class.getName());
        }
    }
    super.setLayoutManager(layout);
}
 
Example 2
Source File: BindItemDecoration.java    From LazyRecyclerAdapter with MIT License 5 votes vote down vote up
/**
 * 配置linear模式的item rect
 */
void linearRect(RecyclerView.LayoutManager layoutManager, RecyclerView parent, View view, Rect outRect) {
    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
    int currentPosition = parent.getChildAdapterPosition(view);
    //去掉header,上下拉item
    if (currentPosition >= offsetPosition && currentPosition < endDataPosition) {
        if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
            if (linearLayoutManager.getReverseLayout()) {
                outRect.left = space;
            } else {
                outRect.right = space;
            }
        } else {
            if (linearLayoutManager.getReverseLayout()) {
                outRect.top = space;
            } else {
                outRect.bottom = space;
            }
        }
    }
    //第一行顶部间隔
    if (needFirstTopEdge && currentPosition == offsetPosition && currentPosition != endDataPosition) {
        if (orientation == LinearLayoutManager.HORIZONTAL) {
            if (linearLayoutManager.getReverseLayout()) {
                outRect.right = space;
            } else {
                outRect.left = space;
            }
        } else {
            if (linearLayoutManager.getReverseLayout()) {
                outRect.bottom = space;
            } else {
                outRect.top = space;
            }
        }
    }
}
 
Example 3
Source File: ListSpacingDecoration.java    From MultiView with Apache License 2.0 5 votes vote down vote up
private boolean isReverseLayout(RecyclerView parent) {
    if (parent.getLayoutManager().getClass().isAssignableFrom(LinearLayoutManager.class)) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
        return layoutManager.getReverseLayout();
    } else {
        throw new IllegalStateException("PaddingItemDecoration can only be used with a LinearLayoutManager.");
    }
}
 
Example 4
Source File: GravitySnapHelper.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAtEdgeOfList(LinearLayoutManager lm) {
    if ((!lm.getReverseLayout() && gravity == Gravity.START)
            || (lm.getReverseLayout() && gravity == Gravity.END)
            || (!lm.getReverseLayout() && gravity == Gravity.TOP)
            || (lm.getReverseLayout() && gravity == Gravity.BOTTOM)) {
        return lm.findLastCompletelyVisibleItemPosition() == lm.getItemCount() - 1;
    } else if (gravity == Gravity.CENTER) {
        return lm.findFirstCompletelyVisibleItemPosition() == 0
                || lm.findLastCompletelyVisibleItemPosition() == lm.getItemCount() - 1;
    } else {
        return lm.findFirstCompletelyVisibleItemPosition() == 0;
    }
}
 
Example 5
Source File: ScrollPageHelper.java    From YCScrollPager with Apache License 2.0 4 votes vote down vote up
@Nullable
private View findStartView(RecyclerView.LayoutManager layoutManager,
                           @NonNull OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        boolean reverseLayout = linearLayoutManager.getReverseLayout();
        int firstChild = reverseLayout ? linearLayoutManager.findLastVisibleItemPosition()
                : linearLayoutManager.findFirstVisibleItemPosition();
        int offset = 1;

        if (layoutManager instanceof GridLayoutManager) {
            offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
        }

        if (firstChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(firstChild);

        float visibleWidth;
        if (isRtlHorizontal) {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        }
        boolean endOfList;
        if (!reverseLayout) {
            endOfList = ((LinearLayoutManager) layoutManager)
                    .findLastCompletelyVisibleItemPosition()
                    == layoutManager.getItemCount() - 1;
        } else {
            endOfList = ((LinearLayoutManager) layoutManager)
                    .findFirstCompletelyVisibleItemPosition()
                    == 0;
        }

        if (visibleWidth > 0.5f && !endOfList) {
            return child;
        } else if (snapLastItem && endOfList) {
            return child;
        } else if (endOfList) {
            return null;
        } else {
            return reverseLayout ? layoutManager.findViewByPosition(firstChild - offset)
                    : layoutManager.findViewByPosition(firstChild + offset);
        }
    }

    return null;
}
 
Example 6
Source File: ScrollPageHelper.java    From YCScrollPager with Apache License 2.0 4 votes vote down vote up
@Nullable
private View findEndView(RecyclerView.LayoutManager layoutManager,
                         @NonNull OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        boolean reverseLayout = linearLayoutManager.getReverseLayout();
        int lastChild = reverseLayout ? linearLayoutManager.findFirstVisibleItemPosition()
                : linearLayoutManager.findLastVisibleItemPosition();
        int offset = 1;

        if (layoutManager instanceof GridLayoutManager) {
            offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
        }

        if (lastChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(lastChild);

        float visibleWidth;

        if (isRtlHorizontal) {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        }

        boolean startOfList;
        if (!reverseLayout) {
            startOfList = ((LinearLayoutManager) layoutManager)
                    .findFirstCompletelyVisibleItemPosition() == 0;
        } else {
            startOfList = ((LinearLayoutManager) layoutManager)
                    .findLastCompletelyVisibleItemPosition()
                    == layoutManager.getItemCount() - 1;
        }

        if (visibleWidth > 0.5f && !startOfList) {
            return child;
        } else if (snapLastItem && startOfList) {
            return child;
        } else if (startOfList) {
            return null;
        } else {
            return reverseLayout ? layoutManager.findViewByPosition(lastChild + offset)
                    : layoutManager.findViewByPosition(lastChild - offset);
        }
    }
    return null;
}
 
Example 7
Source File: ScrollPageHelper.java    From YCBanner with Apache License 2.0 4 votes vote down vote up
@Nullable
private View findStartView(RecyclerView.LayoutManager layoutManager,
                           @NonNull OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        boolean reverseLayout = linearLayoutManager.getReverseLayout();
        int firstChild = reverseLayout ? linearLayoutManager.findLastVisibleItemPosition()
                : linearLayoutManager.findFirstVisibleItemPosition();
        int offset = 1;

        if (layoutManager instanceof GridLayoutManager) {
            offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
        }

        if (firstChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(firstChild);

        float visibleWidth;
        if (isRtlHorizontal) {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        }
        boolean endOfList;
        if (!reverseLayout) {
            endOfList = ((LinearLayoutManager) layoutManager)
                    .findLastCompletelyVisibleItemPosition()
                    == layoutManager.getItemCount() - 1;
        } else {
            endOfList = ((LinearLayoutManager) layoutManager)
                    .findFirstCompletelyVisibleItemPosition()
                    == 0;
        }

        if (visibleWidth > 0.5f && !endOfList) {
            return child;
        } else if (snapLastItem && endOfList) {
            return child;
        } else if (endOfList) {
            return null;
        } else {
            return reverseLayout ? layoutManager.findViewByPosition(firstChild - offset)
                    : layoutManager.findViewByPosition(firstChild + offset);
        }
    }

    return null;
}
 
Example 8
Source File: ScrollPageHelper.java    From YCBanner with Apache License 2.0 4 votes vote down vote up
@Nullable
private View findEndView(RecyclerView.LayoutManager layoutManager,
                         @NonNull OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        boolean reverseLayout = linearLayoutManager.getReverseLayout();
        int lastChild = reverseLayout ? linearLayoutManager.findFirstVisibleItemPosition()
                : linearLayoutManager.findLastVisibleItemPosition();
        int offset = 1;

        if (layoutManager instanceof GridLayoutManager) {
            offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
        }

        if (lastChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(lastChild);

        float visibleWidth;

        if (isRtlHorizontal) {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        }

        boolean startOfList;
        if (!reverseLayout) {
            startOfList = ((LinearLayoutManager) layoutManager)
                    .findFirstCompletelyVisibleItemPosition() == 0;
        } else {
            startOfList = ((LinearLayoutManager) layoutManager)
                    .findLastCompletelyVisibleItemPosition()
                    == layoutManager.getItemCount() - 1;
        }

        if (visibleWidth > 0.5f && !startOfList) {
            return child;
        } else if (snapLastItem && startOfList) {
            return child;
        } else if (startOfList) {
            return null;
        } else {
            return reverseLayout ? layoutManager.findViewByPosition(lastChild + offset)
                    : layoutManager.findViewByPosition(lastChild - offset);
        }
    }
    return null;
}
 
Example 9
Source File: ScrollPageHelper.java    From YCRefreshView with Apache License 2.0 4 votes vote down vote up
@Nullable
private View findStartView(RecyclerView.LayoutManager layoutManager,
                           @NonNull OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        boolean reverseLayout = linearLayoutManager.getReverseLayout();
        int firstChild = reverseLayout ? linearLayoutManager.findLastVisibleItemPosition()
                : linearLayoutManager.findFirstVisibleItemPosition();
        int offset = 1;

        if (layoutManager instanceof GridLayoutManager) {
            offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
        }

        if (firstChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(firstChild);

        float visibleWidth;
        if (isRtlHorizontal) {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        }
        boolean endOfList;
        if (!reverseLayout) {
            endOfList = ((LinearLayoutManager) layoutManager)
                    .findLastCompletelyVisibleItemPosition()
                    == layoutManager.getItemCount() - 1;
        } else {
            endOfList = ((LinearLayoutManager) layoutManager)
                    .findFirstCompletelyVisibleItemPosition()
                    == 0;
        }

        if (visibleWidth > 0.5f && !endOfList) {
            return child;
        } else if (snapLastItem && endOfList) {
            return child;
        } else if (endOfList) {
            return null;
        } else {
            return reverseLayout ? layoutManager.findViewByPosition(firstChild - offset)
                    : layoutManager.findViewByPosition(firstChild + offset);
        }
    }

    return null;
}
 
Example 10
Source File: ScrollPageHelper.java    From YCRefreshView with Apache License 2.0 4 votes vote down vote up
@Nullable
private View findEndView(RecyclerView.LayoutManager layoutManager,
                         @NonNull OrientationHelper helper) {

    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        boolean reverseLayout = linearLayoutManager.getReverseLayout();
        int lastChild = reverseLayout ? linearLayoutManager.findFirstVisibleItemPosition()
                : linearLayoutManager.findLastVisibleItemPosition();
        int offset = 1;

        if (layoutManager instanceof GridLayoutManager) {
            offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
        }

        if (lastChild == RecyclerView.NO_POSITION) {
            return null;
        }

        View child = layoutManager.findViewByPosition(lastChild);

        float visibleWidth;

        if (isRtlHorizontal) {
            visibleWidth = (float) helper.getDecoratedEnd(child)
                    / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
                    / helper.getDecoratedMeasurement(child);
        }

        boolean startOfList;
        if (!reverseLayout) {
            startOfList = ((LinearLayoutManager) layoutManager)
                    .findFirstCompletelyVisibleItemPosition() == 0;
        } else {
            startOfList = ((LinearLayoutManager) layoutManager)
                    .findLastCompletelyVisibleItemPosition()
                    == layoutManager.getItemCount() - 1;
        }

        if (visibleWidth > 0.5f && !startOfList) {
            return child;
        } else if (snapLastItem && startOfList) {
            return child;
        } else if (startOfList) {
            return null;
        } else {
            return reverseLayout ? layoutManager.findViewByPosition(lastChild + offset)
                    : layoutManager.findViewByPosition(lastChild - offset);
        }
    }
    return null;
}