Java Code Examples for android.support.v7.widget.LinearLayoutManager#findFirstCompletelyVisibleItemPosition()
The following examples show how to use
android.support.v7.widget.LinearLayoutManager#findFirstCompletelyVisibleItemPosition() .
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: HomeViewLayer.java From demo4Fish with MIT License | 6 votes |
@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { int count = mDotLayout.getChildCount(); if (0 == count) { return; } LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager(); int position = manager.findFirstCompletelyVisibleItemPosition() % count; for (int i = 0; i < count; i++) { View view = mDotLayout.getChildAt(i); if (i == position) { if (!view.isSelected()) { view.setSelected(true); } } else { if (view.isSelected()) { view.setSelected(false); } } } } }
Example 2
Source File: CommentAdapter.java From Hews with MIT License | 6 votes |
public void collapseChildrenComment(int position) { ArrayList<Comment> childrenComments = new ArrayList<>(); Comment parentComment = (Comment) mItemList.get(position); LinearLayoutManager linearLayoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager(); // if a comment header is not visible when collapsing, scroll to it's header if (position != linearLayoutManager.findFirstCompletelyVisibleItemPosition()) { linearLayoutManager.scrollToPosition(position); } for (int curPosition = position + 1; (mItemList.get(curPosition) instanceof Comment && ((Comment) mItemList.get(curPosition)).getLevel() > parentComment.getLevel()); curPosition++) { childrenComments.add((Comment) mItemList.get(curPosition)); } if (!childrenComments.isEmpty()) { mCollapsedChildrenCommentsIndex.put(parentComment.getCommentId(), childrenComments); for (Comment comment : childrenComments) { mItemList.remove(comment); } notifyItemChanged(position); notifyItemRangeRemoved(position + 1, childrenComments.size()); } }
Example 3
Source File: MonthWeekMaterialCalendarView.java From monthweekmaterialcalendarview with Apache License 2.0 | 5 votes |
/** * 判断线性布局的recyclerView是否到达顶部 * * @param view */ private boolean isAtTop(View view) { boolean isTop = false; if (view instanceof RecyclerView) { if (((RecyclerView) view).getLayoutManager() instanceof ILayoutManager) { if (((RecyclerView) view).getLayoutManager() instanceof LinearLayoutManager) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) ((RecyclerView) view).getLayoutManager(); if (linearLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) { isTop = true; } } if (((RecyclerView) view).getLayoutManager() instanceof GridLayoutManager) { GridLayoutManager gridLayoutManager = (GridLayoutManager) ((RecyclerView) view).getLayoutManager(); if (gridLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) { isTop = true; } } if (((RecyclerView) view).getLayoutManager() instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) ((RecyclerView) view).getLayoutManager(); int[] positions = new int[staggeredGridLayoutManager.getSpanCount()]; staggeredGridLayoutManager.findFirstVisibleItemPositions(positions); if (findMin(positions) == 0) { isTop = true; } } } else { throw new IllegalArgumentException("RecyclerView layoutManager must implement ILayoutManager"); } } return isTop; }
Example 4
Source File: Utils.java From ht-refreshrecyclerview with MIT License | 5 votes |
/** * 获取第一个可见/完全可见item的位置索引 * @param layoutManager RecyclerView.LayoutManager对象 * @param isCompletelyVisible 是否完全可见 * @return item的索引 */ public static int getFirstItemPosition(@NonNull RecyclerView.LayoutManager layoutManager, boolean isCompletelyVisible) { int firstVisibleItemPosition = -1; if (layoutManager instanceof LinearLayoutManager) { //GridLayoutManager继承LinearLayoutManager LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; firstVisibleItemPosition = isCompletelyVisible ? linearLayoutManager.findFirstCompletelyVisibleItemPosition() : linearLayoutManager.findFirstVisibleItemPosition(); } else if (layoutManager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager; int[] firstVisibleItemPositions = isCompletelyVisible ? staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(null) : staggeredGridLayoutManager.findFirstVisibleItemPositions(null); if (firstVisibleItemPositions != null && firstVisibleItemPositions.length > 0) firstVisibleItemPosition = firstVisibleItemPositions[0]; } return firstVisibleItemPosition; }
Example 5
Source File: BounceTouchListener.java From Bounce with Apache License 2.0 | 5 votes |
private boolean hasHitTop() { if (mMainView instanceof ScrollView) { ScrollView scrollView = (ScrollView) mMainView; return scrollView.getScrollY() == 0; } else if (mMainView instanceof ListView) { ListView listView = (ListView) mMainView; if (listView.getAdapter() != null) { if (listView.getAdapter().getCount() > 0) { return listView.getFirstVisiblePosition() == 0 && listView.getChildAt(0).getTop() >= 0; } } } else if (mMainView instanceof RecyclerView) { RecyclerView recyclerView = (RecyclerView) mMainView; if (recyclerView.getAdapter() != null && recyclerView.getLayoutManager() != null) { RecyclerView.Adapter adapter = recyclerView.getAdapter(); if (adapter.getItemCount() > 0) { RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof LinearLayoutManager) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; return linearLayoutManager.findFirstCompletelyVisibleItemPosition() == 0; } else if (layoutManager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager; int[] checks = staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(null); for (int check : checks) { if (check == 0) return true; } } } } } return false; }
Example 6
Source File: TopScrollListener.java From meiShi with Apache License 2.0 | 5 votes |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); if (linearLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) { hasPlay = true; start(); } else if (hasPlay) { hasPlay = false; pause(); } }
Example 7
Source File: GravitySnapHelper.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
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 8
Source File: ScrollManager.java From Mover with Apache License 2.0 | 4 votes |
public boolean isUserNeedInFastScrollUp(RecyclerView view){ LinearLayoutManager manager = (LinearLayoutManager) view.getLayoutManager(); return manager.findFirstCompletelyVisibleItemPosition() >= MIN_VISIBLE_ITEMS; }