Java Code Examples for android.support.v7.widget.RecyclerView#VERTICAL

The following examples show how to use android.support.v7.widget.RecyclerView#VERTICAL . 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: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
private boolean isLastColumn(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        if (columnCount == 1) return true;
        return (position + 1) % columnCount == 0;
    } else {
        if (columnCount == 1) {
            return position + 1 == childCount;
        } else {
            int lastRawItemCount = childCount % columnCount;
            int rawCount = (childCount - lastRawItemCount) / columnCount + (lastRawItemCount > 0 ? 1 : 0);

            int rawPositionJudge = (position + 1) % columnCount;
            if (rawPositionJudge == 0) {
                int positionRaw = (position + 1) / columnCount;
                return rawCount == positionRaw;
            } else {
                int rawPosition = (position + 1 - rawPositionJudge) / columnCount + 1;
                return rawCount == rawPosition;
            }
        }
    }
}
 
Example 2
Source File: Api20ItemDivider.java    From Album with Apache License 2.0 6 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        int orientation = getOrientation(layoutManager);
        int position = parent.getChildLayoutPosition(view);
        int spanCount = getSpanCount(layoutManager);
        int childCount = layoutManager.getItemCount();

        if (orientation == RecyclerView.VERTICAL) {
            offsetVertical(outRect, position, spanCount, childCount);
        } else {
            offsetHorizontal(outRect, position, spanCount, childCount);
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        outRect.set(mWidth, mHeight, mWidth, mHeight); // |-|-
    }
}
 
Example 3
Source File: Api20ItemDivider.java    From Album with Apache License 2.0 6 votes vote down vote up
private boolean isLastRaw(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        if (columnCount == 1) {
            return position + 1 == childCount;
        } else {
            int lastRawItemCount = childCount % columnCount;
            int rawCount = (childCount - lastRawItemCount) / columnCount + (lastRawItemCount > 0 ? 1 : 0);

            int rawPositionJudge = (position + 1) % columnCount;
            if (rawPositionJudge == 0) {
                int positionRaw = (position + 1) / columnCount;
                return rawCount == positionRaw;
            } else {
                int rawPosition = (position + 1 - rawPositionJudge) / columnCount + 1;
                return rawCount == rawPosition;
            }
        }
    } else {
        if (columnCount == 1) return true;
        return (position + 1) % columnCount == 0;
    }
}
 
Example 4
Source File: Api20ItemDivider.java    From Album with Apache License 2.0 6 votes vote down vote up
private boolean isLastColumn(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        if (columnCount == 1) return true;
        return (position + 1) % columnCount == 0;
    } else {
        if (columnCount == 1) {
            return position + 1 == childCount;
        } else {
            int lastRawItemCount = childCount % columnCount;
            int rawCount = (childCount - lastRawItemCount) / columnCount + (lastRawItemCount > 0 ? 1 : 0);

            int rawPositionJudge = (position + 1) % columnCount;
            if (rawPositionJudge == 0) {
                int positionRaw = (position + 1) / columnCount;
                return rawCount == positionRaw;
            } else {
                int rawPosition = (position + 1 - rawPositionJudge) / columnCount + 1;
                return rawCount == rawPosition;
            }
        }
    }
}
 
Example 5
Source File: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent,
    @NonNull RecyclerView.State state) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        int orientation = getOrientation(layoutManager);
        int position = parent.getChildLayoutPosition(view);
        int spanCount = getSpanCount(layoutManager);
        int childCount = layoutManager.getItemCount();

        if (orientation == RecyclerView.VERTICAL) {
            offsetVertical(outRect, position, spanCount, childCount);
        } else {
            offsetHorizontal(outRect, position, spanCount, childCount);
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        outRect.set(mWidth, mHeight, mWidth, mHeight); // |-|-
    }
}
 
Example 6
Source File: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 6 votes vote down vote up
private boolean isLastRaw(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        if (columnCount == 1) {
            return position + 1 == childCount;
        } else {
            int lastRawItemCount = childCount % columnCount;
            int rawCount = (childCount - lastRawItemCount) / columnCount + (lastRawItemCount > 0 ? 1 : 0);

            int rawPositionJudge = (position + 1) % columnCount;
            if (rawPositionJudge == 0) {
                int positionRaw = (position + 1) / columnCount;
                return rawCount == positionRaw;
            } else {
                int rawPosition = (position + 1 - rawPositionJudge) / columnCount + 1;
                return rawCount == rawPosition;
            }
        }
    } else {
        if (columnCount == 1) return true;
        return (position + 1) % columnCount == 0;
    }
}
 
Example 7
Source File: MyDecorationOne.java    From MaterialDesignDemo with MIT License 5 votes vote down vote up
/**
 * 画线
 */
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);
    if (orientation == RecyclerView.HORIZONTAL) {
        drawVertical(c, parent, state);
    } else if (orientation == RecyclerView.VERTICAL) {
        drawHorizontal(c, parent, state);
    }
}
 
Example 8
Source File: MyDecorationOne.java    From MaterialDesignDemo with MIT License 5 votes vote down vote up
/**
 * 设置条目周边的偏移量
 */
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    if (orientation == RecyclerView.HORIZONTAL) {
        //画垂直线
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    } else if (orientation == RecyclerView.VERTICAL) {
        //画水平线
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    }
}
 
Example 9
Source File: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
private boolean isFirstColumn(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        if (columnCount == 1) return true;
        return position % columnCount == 0;
    } else {
        return position < columnCount;
    }
}
 
Example 10
Source File: Api20ItemDivider.java    From Album with Apache License 2.0 5 votes vote down vote up
private int getOrientation(RecyclerView.LayoutManager layoutManager) {
    if (layoutManager instanceof LinearLayoutManager) {
        return ((LinearLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        return ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    }
    return RecyclerView.VERTICAL;
}
 
Example 11
Source File: Api20ItemDivider.java    From Album with Apache License 2.0 5 votes vote down vote up
private boolean isFirstRaw(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        return position < columnCount;
    } else {
        if (columnCount == 1) return true;
        return position % columnCount == 0;
    }
}
 
Example 12
Source File: Api20ItemDivider.java    From Album with Apache License 2.0 5 votes vote down vote up
private boolean isFirstColumn(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        if (columnCount == 1) return true;
        return position % columnCount == 0;
    } else {
        return position < columnCount;
    }
}
 
Example 13
Source File: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
private int getOrientation(RecyclerView.LayoutManager layoutManager) {
    if (layoutManager instanceof LinearLayoutManager) {
        return ((LinearLayoutManager)layoutManager).getOrientation();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        return ((StaggeredGridLayoutManager)layoutManager).getOrientation();
    }
    return RecyclerView.VERTICAL;
}
 
Example 14
Source File: DefaultItemDecoration.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
private boolean isFirstRaw(int orientation, int position, int columnCount, int childCount) {
    if (orientation == RecyclerView.VERTICAL) {
        return position < columnCount;
    } else {
        if (columnCount == 1) return true;
        return position % columnCount == 0;
    }
}
 
Example 15
Source File: StoryFragment.java    From yahnac with Apache License 2.0 4 votes vote down vote up
private RecyclerView.LayoutManager createLayoutManager(Resources resources) {
    int spans = resources.getInteger(R.integer.feed_columns);
    return new StaggeredGridLayoutManager(spans, RecyclerView.VERTICAL);
}
 
Example 16
Source File: BookmarksFragment.java    From yahnac with Apache License 2.0 4 votes vote down vote up
private RecyclerView.LayoutManager createLayoutManager(Resources resources) {
    int spans = resources.getInteger(R.integer.feed_columns);
    return new StaggeredGridLayoutManager(spans, RecyclerView.VERTICAL);
}
 
Example 17
Source File: BindingUtils.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@BindingAdapter("layout_vertical")
public static void bindLayoutManager(@NonNull RecyclerView recyclerView, boolean vertical) {
    int orientation = vertical ? RecyclerView.VERTICAL : RecyclerView.HORIZONTAL;
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext(), orientation, false));
}
 
Example 18
Source File: PathLayoutManager.java    From PathLayoutManager with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canScrollVertically() {
    return mOrientation == RecyclerView.VERTICAL;
}
 
Example 19
Source File: PathLayoutManager.java    From PathLayoutManager with Apache License 2.0 4 votes vote down vote up
/**
 * 根据当前设置的滚动方向来获取对应的滚动偏移量
 */
private float getScrollOffset() {
    return mOrientation == RecyclerView.VERTICAL ? mOffsetY : mOffsetX;
}
 
Example 20
Source File: PathLayoutManager.java    From PathLayoutManager with Apache License 2.0 2 votes vote down vote up
/**
 * @param path       目标路径
 * @param itemOffset Item间距
 */
public PathLayoutManager(Path path, int itemOffset) {
    this(path, itemOffset, RecyclerView.VERTICAL);
}