android.support.v7.widget.RecyclerView Java Examples
The following examples show how to use
android.support.v7.widget.RecyclerView.
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: MoverRecycleFragment.java From Mover with Apache License 2.0 | 6 votes |
@Override public boolean onItemLongClick(RecyclerView parent, View view, int position, long id) { int viewType = mWatchMeAdapter.getItemViewType(position); switch (viewType){ case WatchMeAdapterNew.TYPE_HEADER_FIRST: getJobManager().addJob(new FetchAvailableVideoQualities("p3xpwfHm")); return true; case WatchMeAdapterNew.TYPE_VIDEO: case WatchMeAdapterNew.TYPE_VIDEO_LAST: mSelectedVideoPosition = position; PopupMenu popupMenu = new PopupMenu(view.getContext(), view, Gravity.TOP); popupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener); popupMenu.inflate(R.menu.video_item_menu); popupMenu.show(); return true; } return false; }
Example #2
Source File: SmartRecycleView.java From AutoRecycleView with Apache License 2.0 | 6 votes |
public SmartRecycleView setLayoutManger(LayoutManagerType layoutManagerType, int orientation, int spanCout) { RecyclerView.LayoutManager layoutManager = null; if (layoutManagerType == LayoutManagerType.LINEAR_LAYOUT) { LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext); linearLayoutManager.setOrientation(orientation); layoutManager = linearLayoutManager; } else if (layoutManagerType == LayoutManagerType.GRID_LAYOUT) { GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, spanCout); gridLayoutManager.setOrientation(orientation); layoutManager = gridLayoutManager; } else if (layoutManagerType == LayoutManagerType.STAGGER_LAYOUT) { StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(spanCout, orientation); layoutManager = staggeredGridLayoutManager; } mRecyclerView.setLayoutManager(layoutManager); return this; }
Example #3
Source File: RecyclerViewEspressoFactory.java From ChipsLayoutManager with Apache License 2.0 | 6 votes |
private static Matcher<View> orderMatcher() { return new TypeSafeMatcher<View>() { @Override public void describeTo(Description description) { description.appendText("with correct position order"); } @Override public boolean matchesSafely(View v) { RecyclerView view = (RecyclerView) v; if (view.getLayoutManager() == null) return false; ChildViewsIterable childViews = new ChildViewsIterable(view.getLayoutManager()); int pos = view.getChildAdapterPosition(childViews.iterator().next()); for (View child : childViews) { if (pos != view.getChildAdapterPosition(child)) { return false; } pos ++; } return true; } }; }
Example #4
Source File: LRecyclerView.java From luckly_recyclerview with MIT License | 6 votes |
@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; final int spanCount = gridLayoutManager.getSpanCount(); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { // 如果当前是footer的位置,那么该item占据一行的个单元格,正常情况下占据1个单元格 if (getItemViewType(position) == FOOTER_TYPE) { return spanCount; } else if (isRefreshHeader(position) || getItemViewType(position) == getHeaderTypeByPosition(position - 1)) { return spanCount; } else { return 1; } } }); } mAdapter.onAttachedToRecyclerView(recyclerView); }
Example #5
Source File: ExposeLinearLayoutManagerEx.java From vlayout with MIT License | 6 votes |
/** * @return The final offset amount for children */ private int fixLayoutEndGapExpose(int endOffset, RecyclerView.Recycler recycler, RecyclerView.State state, boolean canOffsetChildren) { int gap = mOrientationHelper.getEndAfterPadding() - endOffset; int fixOffset = 0; if (gap > 0) { fixOffset = -scrollInternalBy(-gap, recycler, state); } else { return 0; // nothing to fix } // move offset according to scroll amount endOffset += fixOffset; if (canOffsetChildren) { // re-calculate gap, see if we could fix it gap = mOrientationHelper.getEndAfterPadding() - endOffset; if (gap > 0) { mOrientationHelper.offsetChildren(gap); return gap + fixOffset; } } return fixOffset; }
Example #6
Source File: MyRoutesRecyclerAdapter.java From kute with Apache License 2.0 | 6 votes |
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { switch (holder.getItemViewType()) { case header: configureRecyclerHead((HeaderRecyclerViewHolder)holder); break; case general_list_item: configureGeneralItem((MyRoutesItemViewHolder)holder,position); break; default: configureGeneralItem((MyRoutesItemViewHolder)holder,position); break; } }
Example #7
Source File: MultiTypeLoadMoreAdapter.java From AndroidUiKit with Apache License 2.0 | 6 votes |
@Override public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { loadMoreDelegate.attach(recyclerView); final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager == null) { Log.e(TAG, "Cannot setSpanSizeLookup on a null LayoutManager Object. " + "Call setLayoutManager with a non-null argument."); return; } if (layoutManager instanceof GridLayoutManager) { ((GridLayoutManager) layoutManager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { Object obj = getItems().get(position); return obj.getClass().equals(LoadMoreItem.class) ? ((GridLayoutManager) layoutManager).getSpanCount() : 1; } }); } }
Example #8
Source File: MainActivity.java From LiveSourceCode with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); findViewById(R.id.btn_request).setOnClickListener(onClickListener); findViewById(R.id.btn_select_image).setOnClickListener(onClickListener); mTvResult = (TextView) findViewById(R.id.tv_result); mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view); mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.set(5, 5, 5, 5); } }); mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3)); int size = measureSize(); mAdapter = new AlbumPreviewAdapter(this, size); mRecyclerView.setAdapter(mAdapter); }
Example #9
Source File: WRLinearLayoutManager.java From RecyclerViewHelper with MIT License | 6 votes |
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec, int heightSpec, int[] measuredDimension) { View view = recycler.getViewForPosition(position); // For adding Item Decor Insets to view super.measureChildWithMargins(view, 0, 0); RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams(); int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, getPaddingLeft() + getPaddingRight() + getDecoratedLeft(view) + getDecoratedRight(view), p.width); int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, getPaddingTop() + getPaddingBottom() + getPaddingBottom() + getDecoratedBottom(view), p.height); view.measure(childWidthSpec, childHeightSpec); // Get decorated measurements measuredDimension[0] = getDecoratedMeasuredWidth(view) + p.leftMargin + p.rightMargin; measuredDimension[1] = getDecoratedMeasuredHeight(view) + p.bottomMargin + p.topMargin; recycler.recycleView(view); }
Example #10
Source File: LuGridItemDecoration.java From LRecyclerView with Apache License 2.0 | 6 votes |
public void drawVertical(Canvas c, RecyclerView parent) { final int childCount = parent.getChildCount(); LuRecyclerViewAdapter adapter = (LuRecyclerViewAdapter) parent.getAdapter(); for (int i = 0; i < childCount; i++) { if (adapter.isHeader(i) || adapter.isFooter(i)) { c.drawRect(0, 0, 0, 0, mPaint); } else { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int top = child.getTop(); final int bottom = child.getBottom() + verticalSpace; final int left = child.getRight() + params.rightMargin; final int right = left + horizontalSpace; c.drawRect(left, top, right, bottom, mPaint); } } }
Example #11
Source File: ReItemTouchHelper.java From ReSwipeCard with Apache License 2.0 | 6 votes |
private void addChildDrawingOrderCallback() { if (Build.VERSION.SDK_INT >= 21) { return;// we use elevation on Lollipop } if (mChildDrawingOrderCallback == null) { mChildDrawingOrderCallback = new RecyclerView.ChildDrawingOrderCallback() { @Override public int onGetChildDrawingOrder(int childCount, int i) { if (mOverdrawChild == null) { return i; } int childPosition = mOverdrawChildPosition; if (childPosition == -1) { childPosition = mRecyclerView.indexOfChild(mOverdrawChild); mOverdrawChildPosition = childPosition; } if (i == childCount - 1) { return childPosition; } return i < childPosition ? i : i + 1; } }; } mRecyclerView.setChildDrawingOrderCallback(mChildDrawingOrderCallback); }
Example #12
Source File: PinnedHeaderDecoration.java From RxTools-master with Apache License 2.0 | 6 votes |
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { createPinnedHeader(parent); if (mPinnedHeaderView != null) { int headerEndAt = mPinnedHeaderView.getTop() + mPinnedHeaderView.getHeight(); View v = parent.findChildViewUnder(c.getWidth() / 2, headerEndAt + 1); if (isPinnedView(parent, v)) { mPinnedHeaderTop = v.getTop() - mPinnedHeaderView.getHeight(); } else { mPinnedHeaderTop = 0; } mClipBounds = c.getClipBounds(); mClipBounds.top = mPinnedHeaderTop + mPinnedHeaderView.getHeight(); c.clipRect(mClipBounds); } }
Example #13
Source File: TabLayoutSupport.java From RecyclerViewPager with Apache License 2.0 | 5 votes |
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { TabLayout tabLayout = this.mTabLayoutRef.get(); final RecyclerViewPager viewPager = (RecyclerViewPager) recyclerView; final int pagerWidth = recyclerView.getWidth() - recyclerView.getPaddingLeft() - recyclerView.getPaddingRight(); final View centerXChild = ViewUtils.getCenterXChild(viewPager); if (centerXChild == null) { return; } int centerChildPosition = viewPager.getChildAdapterPosition(centerXChild); float offset = mPagerLeftBeforeScroll - centerXChild.getLeft() + pagerWidth * (centerChildPosition - mPositionBeforeScroll); final float positionOffset = offset * 1f / pagerWidth; if (tabLayout != null) { if (positionOffset < 0) { try { tabLayout.setScrollPosition(mPositionBeforeScroll + (int) Math.floor(positionOffset), positionOffset - (int) Math.floor(positionOffset), false); } catch (Throwable e) { e.printStackTrace(); } } else { tabLayout.setScrollPosition(mPositionBeforeScroll + (int) (positionOffset), positionOffset - (int) (positionOffset), false); } } Log.d("test", "dx:" + positionOffset); }
Example #14
Source File: Divider.java From RecyclerViewDemo with Apache License 2.0 | 5 votes |
public void drawHorizontal(Canvas c, RecyclerView parent) { final int top = parent.getPaddingTop() + topMargin; final int bottom = parent.getHeight() - parent.getPaddingBottom() - bottomMargin; final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child .getLayoutParams(); final int left = child.getRight() + params.rightMargin + leftMargin; final int right = left + width; mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example #15
Source File: NavigationFragment.java From Awesome-WanAndroid with Apache License 2.0 | 5 votes |
/** * Right recyclerView linkage left tabLayout * SCROLL_STATE_IDLE just call once * * @param newState RecyclerView new scroll state */ private void rightLinkageLeft(int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (isClickTab) { isClickTab = false; return; } int firstPosition = mManager.findFirstVisibleItemPosition(); if (index != firstPosition) { index = firstPosition; setChecked(index); } } }
Example #16
Source File: RecyclerScrollMoreListener.java From ChatKit with Apache License 2.0 | 5 votes |
@Override public void onScrolled(RecyclerView view, int dx, int dy) { if (loadMoreListener != null) { int lastVisibleItemPosition = 0; int totalItemCount = mLayoutManager.getItemCount(); if (mLayoutManager instanceof StaggeredGridLayoutManager) { int[] lastVisibleItemPositions = ((StaggeredGridLayoutManager) mLayoutManager).findLastVisibleItemPositions(null); lastVisibleItemPosition = getLastVisibleItem(lastVisibleItemPositions); } else if (mLayoutManager instanceof LinearLayoutManager) { lastVisibleItemPosition = ((LinearLayoutManager) mLayoutManager).findLastVisibleItemPosition(); } else if (mLayoutManager instanceof GridLayoutManager) { lastVisibleItemPosition = ((GridLayoutManager) mLayoutManager).findLastVisibleItemPosition(); } if (totalItemCount < previousTotalItemCount) { this.currentPage = 0; this.previousTotalItemCount = totalItemCount; if (totalItemCount == 0) { this.loading = true; } } if (loading && (totalItemCount > previousTotalItemCount)) { loading = false; previousTotalItemCount = totalItemCount; } int visibleThreshold = 5; if (!loading && (lastVisibleItemPosition + visibleThreshold) > totalItemCount) { currentPage++; loadMoreListener.onLoadMore(loadMoreListener.getMessagesCount(), totalItemCount); loading = true; } } }
Example #17
Source File: ListFragment.java From Jide-Note with MIT License | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_list, container, false); fab = (ButtonFloat) view.findViewById(R.id.new_edit_fab); fab.setOnClickListener(this); recyclerView = (RecyclerView) view.findViewById(R.id.list_recyclerview); initRecyclerView(); LogUtils.e("onCreateView"); return view; }
Example #18
Source File: MainActivity.java From Rocko-Android-Demos with Apache License 2.0 | 5 votes |
private void init() { mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); setTitle(R.string.app_name); mToolbar.setTitleTextColor(Color.WHITE); mFabButton = (ImageButton) findViewById(R.id.fab); mFabButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FAB", Toast.LENGTH_SHORT).show(); } }); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); RecyclerAdapter recyclerAdapter = new RecyclerAdapter(createItemList()); recyclerView.setAdapter(recyclerAdapter); recyclerView.setOnScrollListener(new HidingScrollListener() { @Override public void onHide() { hideViews(); } @Override public void onShow() { showViews(); } }); }
Example #19
Source File: SevenActivity.java From YCBanner with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_seven); mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView); mRecyclerView2 = (RecyclerView) findViewById(R.id.recyclerView2); mRecyclerView3 = (RecyclerView) findViewById(R.id.recyclerView3); mRecyclerView4 = (RecyclerView) findViewById(R.id.recyclerView4); initRecyclerView(); initRecyclerView2(); initRecyclerView3(); initRecyclerView4(); }
Example #20
Source File: BookshelfFragment.java From MaterialHome with Apache License 2.0 | 5 votes |
@Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { if (mBookshelfs.isEmpty()) { return; } int position = viewHolder.getAdapterPosition(); final Bookshelf bookshelf = mBookshelfs.get(position); bookshelf.setIndex(position); queue.add(bookshelf); mBookshelfs.remove(position); mbookshelfAdapter.notifyItemRemoved(position); }
Example #21
Source File: BindDragCallBack.java From LazyRecyclerAdapter with MIT License | 5 votes |
@Override public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { final int dragFlags; final int swipeFlags; if (recyclerView.getLayoutManager() instanceof GridLayoutManager || recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) { dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT; swipeFlags = 0; } else { dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; swipeFlags = mSwipeFlags; } return makeMovementFlags(dragFlags, swipeFlags); }
Example #22
Source File: HeaderViewRecyclerAdapter.java From HeroVideo-master with Apache License 2.0 | 5 votes |
private void setWrappedAdapter(RecyclerView.Adapter adapter) { if (mWrappedAdapter != null) mWrappedAdapter.unregisterAdapterDataObserver(mDataObserver); mWrappedAdapter = adapter; Class adapterClass = mWrappedAdapter.getClass(); if (!mItemTypesOffset.containsKey(adapterClass)) putAdapterTypeOffset(adapterClass); mWrappedAdapter.registerAdapterDataObserver(mDataObserver); }
Example #23
Source File: RecycleViewFragment.java From OptionRoundCardview with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //int section = getArguments().getInt(ARG_SECTION_NUMBER); View rootView = inflater.inflate(R.layout.fragment_rv, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.rv_list); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); mAdapter = new SimpleAdapter(); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mAdapter.add("jordyamc"); mRecyclerView.setAdapter(mAdapter); return rootView; }
Example #24
Source File: SimpleItemTouchHelperCallback.java From clear-todolist with GNU General Public License v3.0 | 5 votes |
@Override public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { super.clearView(recyclerView, viewHolder); viewHolder.itemView.setAlpha(ALPHA_FULL); if (viewHolder instanceof ItemTouchHelperViewHolder) { // Tell the view holder it's time to restore the idle state ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder; itemViewHolder.onItemClear(); } }
Example #25
Source File: VideoFragment.java From MicroReader with MIT License | 5 votes |
private void initView() { swipeRefreshLayout.setOnRefreshListener(this); setSwipeRefreshLayoutColor(swipeRefreshLayout); mLinearLayoutManager = new LinearLayoutManager(getActivity()); swipeTarget.setLayoutManager(mLinearLayoutManager); swipeTarget.setHasFixedSize(true); swipeTarget.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (dy > 0) //向下滚动 { visibleItemCount = mLinearLayoutManager.getChildCount(); totalItemCount = mLinearLayoutManager.getItemCount(); pastVisiblesItems = mLinearLayoutManager.findFirstVisibleItemPosition(); if (!loading && (visibleItemCount + pastVisiblesItems) >= totalItemCount) { loading = true; onLoadMore(); } } } }); videoAdapter = new VideoAdapter(getActivity(), mWeiboVideoBlogs); swipeTarget.setAdapter(videoAdapter); mIVideoPresenter.getVideoFromCache(1); if (SharePreferenceUtil.isRefreshOnlyWifi(getActivity())) { if (NetWorkUtil.isWifiConnected(getActivity())) { onRefresh(); } else { Toast.makeText(getActivity(), getString(R.string.toast_wifi_refresh_data), Toast.LENGTH_SHORT).show(); } } else { onRefresh(); } }
Example #26
Source File: RecyclerViewFragment.java From ClockPlus with GNU General Public License v3.0 | 5 votes |
public final void performScrollToStableId(long stableId) { if (stableId != RecyclerView.NO_ID) { int position = -1; for (int i = 0; i < mAdapter.getItemCount(); i++) { if (mAdapter.getItemId(i) == stableId) { position = i; break; } } if (position >= 0) { scrollToPosition(position); onScrolledToStableId(stableId, position); } } }
Example #27
Source File: FgLinearLayoutManager.java From fingen with Apache License 2.0 | 5 votes |
@Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { try { super.onLayoutChildren(recycler, state); } catch (IndexOutOfBoundsException e) { Log.e("Error", "IndexOutOfBoundsException in RecyclerView happens"); } }
Example #28
Source File: RecyclerViewItemCountAssertion.java From espresso-macchiato with MIT License | 5 votes |
@Override public void check(View view, NoMatchingViewException noViewFoundException) { if (noViewFoundException != null) { throw noViewFoundException; } RecyclerView recyclerView = (RecyclerView) view; RecyclerView.Adapter adapter = recyclerView.getAdapter(); assertThat(adapter.getItemCount(), is(expectedCount)); }
Example #29
Source File: Tests.java From Crimson with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tests, container, false); progressBar = (ProgressBar) view.findViewById(R.id.progress); recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview); LinearLayoutManager llm = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(llm); return view; }
Example #30
Source File: RecyclerViewOnItemClickListener.java From custom-searchable with Apache License 2.0 | 5 votes |
@Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { View childView = view.findChildViewUnder(e.getX(), e.getY()); if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) { mListener.onItemClick(childView, view.getChildPosition(childView)); } return false; }