android.support.v7.widget.GridLayoutManager Java Examples
The following examples show how to use
android.support.v7.widget.GridLayoutManager.
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: PayActivity.java From Mobike with Apache License 2.0 | 6 votes |
private void initView() { mIntegers.add(100); mIntegers.add(50); mIntegers.add(20); mIntegers.add(10); mIntegers.add(5); final List<String> mData = new ArrayList<>(); for (int i = 0; i < chargetext.length; i++) { mData.add(chargetext[i]); } mAdapter = new ChargeAmountAdapter(this, mData); mRecyclerview.setAdapter(mAdapter); mRecyclerview.setLayoutManager(new GridLayoutManager(this, 2)); mAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() { @Override public void onClick(View v, int position) { mAdapter.setSelectPosition(position); } }); }
Example #2
Source File: WrapperAdapter.java From youqu_master with Apache License 2.0 | 6 votes |
@Override public void onAttachedToRecyclerView(final RecyclerView recyclerView) { RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager; gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { WrapperAdapter wrapperAdapter = (WrapperAdapter) recyclerView.getAdapter(); if (isFullSpanType(wrapperAdapter.getItemViewType(position))) { return gridLayoutManager.getSpanCount(); } return 1; } }); } }
Example #3
Source File: MGridLayoutManager.java From meiShi with Apache License 2.0 | 6 votes |
public MGridLayoutManager(Context context, final int spanCount, final BaseLoadMoreRecyclerAdapter mAdapter) { super(context, spanCount); setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch (mAdapter.getItemViewType(position)) { case BaseLoadMoreRecyclerAdapter.TYPE_FOOTER: return spanCount; case BaseLoadMoreRecyclerAdapter.TYPE_ITEM: return 1; default: return -1; } } }); }
Example #4
Source File: CategoriesGridAdapter.java From outlay with Apache License 2.0 | 6 votes |
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { Context context = parent.getContext(); final LayoutInflater inflater = LayoutInflater.from(context); switch (viewType) { case HEADER: final View numpadView = inflater.inflate(app.outlay.R.layout.recycler_numpad, parent, false); GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) numpadView.getLayoutParams(); params.height = parent.getMeasuredHeight() - (context.getResources().getDimensionPixelSize(app.outlay.R.dimen.category_item_height) * 2); final NumpadViewHolder viewHolder = new NumpadViewHolder(numpadView); return viewHolder; default: final View catView = inflater.inflate(app.outlay.R.layout.item_category, parent, false); final CategoryViewHolder categoryViewHolder = new CategoryViewHolder(catView); return categoryViewHolder; } }
Example #5
Source File: DividerGridItemDecoration.java From CoordinatorLayoutExample with Apache License 2.0 | 6 votes |
private boolean isLastColum(RecyclerView parent, int pos, int spanCount, int childCount) { LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { if ((pos + 1) % spanCount == 0) // 如果是最后一列,则不需要绘制右边 { return true; } } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边 { return true; } } else { childCount = childCount - childCount % spanCount; if (pos >= childCount)// 如果是最后一列,则不需要绘制右边 return true; } } return false; }
Example #6
Source File: IconsFragment.java From NanoIconPack with Apache License 2.0 | 6 votes |
private void init() { Bundle bundle = getArguments(); pageId = bundle.getInt("pageId"); iconsGetter = (IconsGetter) bundle.getSerializable("iconsGetter"); gridItemMode = bundle.getInt("mode", IconAdapter.MODE_ICON); RecyclerView recyclerView = (RecyclerView) contentView.findViewById(R.id.recycler_view); int[] gridNumAndWidth = calculateGridNumAndWidth(); recyclerView.setLayoutManager(new GridLayoutManager(getContext(), gridNumAndWidth[0])); iconAdapter = new IconAdapter(getContext(), gridNumAndWidth[1]); iconAdapter.setMode(gridItemMode); iconAdapter.setOnItemClickListener(new IconAdapter.OnItemClickListener() { @Override public void onClick(int pos, IconBean bean) { IconDialog.newInstance(bean, ExtraUtil.isFromLauncherPick(getActivity().getIntent())) .show(getFragmentManager(), "iconDialog"); } }); recyclerView.setAdapter(iconAdapter); }
Example #7
Source File: MainActivity.java From example with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.inject(this); coverItems = new ArrayList<>(); coverItems.add(new CoverItem("Raisa", R.drawable.coveralbum_raisa)); coverItems.add(new CoverItem("Tulus", R.drawable.coveralbum_tulus)); coverItems.add(new CoverItem("D'Masive", R.drawable.coveralbum_dmasive)); coverItems.add(new CoverItem("Skrillex", R.drawable.coveralbum_skrillex)); coverItems.add(new CoverItem("Angger Dimas", R.drawable.coveralbum_angger)); adapter = new CoverAdapter(this, coverItems); GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2); recyclerView.setLayoutManager(gridLayoutManager); recyclerView.setAdapter(adapter); }
Example #8
Source File: AlbumActivity.java From Album with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_album); mToolbar = findViewById(R.id.toolbar); setSupportActionBar(mToolbar); mTvMessage = findViewById(R.id.tv_message); RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new GridLayoutManager(this, 3)); Divider divider = new Api21ItemDivider(Color.TRANSPARENT, 10, 10); recyclerView.addItemDecoration(divider); mAdapter = new Adapter(this, new OnItemClickListener() { @Override public void onItemClick(View view, int position) { previewAlbum(position); } }); recyclerView.setAdapter(mAdapter); }
Example #9
Source File: ImageGridActivity.java From ImagePicker with Apache License 2.0 | 6 votes |
@Override public void onImagesLoaded(List<ImageFolder> imageFolders) { this.mImageFolders = imageFolders; imagePicker.setImageFolders(imageFolders); if (imageFolders.size() == 0) { // mImageGridAdapter.refreshData(null); mRecyclerAdapter.refreshData(null); } else { // mImageGridAdapter.refreshData(imageFolders.get(0).images); mRecyclerAdapter.refreshData(imageFolders.get(0).images); } // mImageGridAdapter.setOnImageItemClickListener(this); mRecyclerAdapter.setOnImageItemClickListener(this); mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3)); mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(3, Utils.dp2px(this, 2), false)); mRecyclerView.setAdapter(mRecyclerAdapter); mImageFolderAdapter.refreshData(imageFolders); }
Example #10
Source File: LiveMainActivity.java From KSYMediaPlayer_Android with Apache License 2.0 | 6 votes |
private void initView() { qRcode = (ImageView) findViewById(R.id.QRcode); qRcode.setOnClickListener(this); config = (ImageView) findViewById(R.id.config); config.setOnClickListener(this); title = (RelativeLayout) findViewById(R.id.title); recyclerView = (RecyclerView) findViewById(R.id.vod_main_recycler); layoutManager = new GridLayoutManager(this, 2); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position == 0) { return layoutManager.getSpanCount(); } else { return 1; } } }); recyclerView.setLayoutManager(layoutManager); }
Example #11
Source File: MainActivity.java From YTS with MIT License | 6 votes |
private void activateEndlessScroll(RecyclerView recyclerView, GridLayoutManager manager) { RxRecyclerView.scrollEvents(recyclerView) .subscribe(scrollEvent -> { visibleItemCount = recyclerView.getChildCount(); totalItemCount = manager.getItemCount(); firstVisibleItem = manager.findFirstVisibleItemPosition(); if (loading) { if (totalItemCount > previousTotal) { loading = false; previousTotal = totalItemCount; } } if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) { pageNum++; presenter.loadMoviesList(getContext(), pageNum, false); loading = true; } }); }
Example #12
Source File: EndlessRecyclerView.java From materialup with Apache License 2.0 | 6 votes |
/** * if layout manager do not have this method , will return 0 * * @return */ public int findFirstVisibleItemPosition() { LayoutManager manager = getLayoutManager(); int firstVisibleItems = 0; if (manager instanceof LinearLayoutManager) { firstVisibleItems = ((LinearLayoutManager) manager).findFirstVisibleItemPosition(); } else if (manager instanceof GridLayoutManager) { firstVisibleItems = ((GridLayoutManager) manager).findFirstVisibleItemPosition(); } else if (manager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager sg = ((StaggeredGridLayoutManager) manager); int[] items = new int[sg.getSpanCount()]; items = ((StaggeredGridLayoutManager) manager).findFirstVisibleItemPositions(items); firstVisibleItems = items[0]; } return firstVisibleItems; }
Example #13
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 #14
Source File: VideoActivity.java From Album with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_album); mToolbar = findViewById(R.id.toolbar); setSupportActionBar(mToolbar); mTvMessage = findViewById(R.id.tv_message); RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new GridLayoutManager(this, 3)); Divider divider = new Api21ItemDivider(Color.TRANSPARENT, 10, 10); recyclerView.addItemDecoration(divider); mAdapter = new Adapter(this, new OnItemClickListener() { @Override public void onItemClick(View view, int position) { previewVideo(position); } }); recyclerView.setAdapter(mAdapter); }
Example #15
Source File: PageMenuLayout.java From PageMenuLayout with Apache License 2.0 | 6 votes |
public void setPageDatas(int rowCount, int spanCount, @NonNull List<T> datas, @NonNull PageMenuViewHolderCreator creator) { if (datas == null) { datas = new ArrayList<>(); } mRowCount = rowCount; mSpanCount = spanCount; if (mRowCount == 0 || mSpanCount == 0) { return; } int pageSize = mRowCount * mSpanCount; int pageCount = (int) Math.ceil(datas.size() * 1.0 / pageSize); List<View> viewList = new ArrayList<>(); for (int index = 0; index < pageCount; index++) { RecyclerView recyclerView = new RecyclerView(this.getContext()); recyclerView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); recyclerView.setLayoutManager(new GridLayoutManager(this.getContext(), mSpanCount)); EntranceAdapter<T> entranceAdapter = new EntranceAdapter<>(creator, datas, index, pageSize); recyclerView.setAdapter(entranceAdapter); viewList.add(recyclerView); } PageViewPagerAdapter adapter = new PageViewPagerAdapter(viewList); mViewPager.setAdapter(adapter); }
Example #16
Source File: IndexTabDelegate.java From FastWaiMai with MIT License | 6 votes |
@Override public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View view) { RestClient.builder() .url("api/youlike") .loader(getContext()) .success(new ISuccess() { @Override public void onSuccess(String response) { final GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(),2); mTabReclclerView.setLayoutManager(gridLayoutManager); final List<MultipleItemEntity> data = new ShopCartLikeConverter().setJsonData(response).convert(); final ShopCartLikeAdapter likeAdapter = new ShopCartLikeAdapter(data); mTabReclclerView.setAdapter(likeAdapter); mTabReclclerView.addOnItemTouchListener(IndexItemClickListener.create(IndexTabDelegate.this)); } }) .build() .get(); }
Example #17
Source File: GridFragment.java From RecyclerView_Divider with Apache License 2.0 | 6 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { mRecyclerView = (RecyclerView) view; GridLayoutManager layoutManager = new GridLayoutManager(view.getContext(), span); mRecyclerView.setLayoutManager(layoutManager); adapter = new GridAdapter(list); mRecyclerView.setAdapter(adapter); DividerItemDecoration itemDecoration = new DividerItemDecoration(); itemDecoration.setDividerLookup(new AgileDividerLookup()); mRecyclerView.addItemDecoration(itemDecoration); if (type == MainActivity.TYPE_AGILE) { layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { return span / adapter.getItemViewType(position); } }); } }
Example #18
Source File: LoadMoreRecyclerView.java From LoadMoreRecyclerView with Apache License 2.0 | 6 votes |
/** * 获取第一条展示的位置 * * @return */ private int getFirstVisiblePosition() { int position; if (getLayoutManager() instanceof LinearLayoutManager) { position = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition(); } else if (getLayoutManager() instanceof GridLayoutManager) { position = ((GridLayoutManager) getLayoutManager()).findFirstVisibleItemPosition(); } else if (getLayoutManager() instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager(); int[] lastPositions = layoutManager.findFirstVisibleItemPositions(new int[layoutManager.getSpanCount()]); position = getMinPositions(lastPositions); } else { position = 0; } return position; }
Example #19
Source File: RecyclerArrayAdapter.java From YCRefreshView with Apache License 2.0 | 5 votes |
/** * 页面进入时,显示RecyclerView,调用onAttachedToRecyclerView,做一些注册工作; * 页面退出时,销毁RecyclerView,调用onDetachedFromRecyclerView,做一些解注册和其他资源回收的操作。 * @param recyclerView recyclerView */ @Override public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); //增加对RecyclerArrayAdapter奇葩操作的修复措施 registerAdapterDataObserver(new FixDataObserver(recyclerView)); if (mSetHeaderAndFooterSpan){ //下面是处理grid试图上拉加载的问题 RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager instanceof GridLayoutManager) { final GridLayoutManager gridManager = ((GridLayoutManager) manager); gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { // 如果当前是footer的位置,那么该item占据2个单元格,正常情况下占据1个单元格 int itemViewType = getItemViewType(position); //注意,具体可以看DefaultEventDelegate类中的EventFooter类代码 //如果是头部header或者底部footer,则直接 if (itemViewType>=DefaultEventDelegate.EventFooter.HIDE && itemViewType<=DefaultEventDelegate.EventFooter.SHOW_NO_MORE){ RefreshLogUtils.d("onAttachedToRecyclerView----这个是header和footer"); return gridManager.getSpanCount(); }else { RefreshLogUtils.d("onAttachedToRecyclerView----"); return 1; } } }); } } }
Example #20
Source File: MainActivity.java From ImageLoadPK with Apache License 2.0 | 5 votes |
private void initView() { Drawables.init(getResources()); mWatchListener = new WatchListener(); mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2)); mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { clearOtherLoader(); mRefreshLayout.setRefreshing(false); } }); }
Example #21
Source File: MainActivity.java From android-list-to-grid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.getItemAnimator().setChangeDuration(700); simpleAdapter = new SimpleAdapter(); recyclerView.setAdapter(simpleAdapter); gridLayoutManager = new GridLayoutManager(this, 1); recyclerView.setLayoutManager(gridLayoutManager); }
Example #22
Source File: BeatBoxFragment.java From AndroidProgramming3e with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { FragmentBeatBoxBinding binding = DataBindingUtil .inflate(inflater, R.layout.fragment_beat_box, container, false); binding.recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3)); binding.recyclerView.setAdapter(new SoundAdapter(mBeatBox.getSounds())); return binding.getRoot(); }
Example #23
Source File: DividerGridItemDecoration.java From RecyclerViewEvent with Apache License 2.0 | 5 votes |
private int getSpanCount(RecyclerView parent) { // 列数 int spanCount = -1; RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { spanCount = ((GridLayoutManager) layoutManager).getSpanCount(); } else if (layoutManager instanceof StaggeredGridLayoutManager) { spanCount = ((StaggeredGridLayoutManager) layoutManager) .getSpanCount(); } return spanCount; }
Example #24
Source File: GiftPopup.java From EasyPopup with Apache License 2.0 | 5 votes |
@Override protected void initViews(View view, GiftPopup basePopup) { mRecyclerView = findViewById(R.id.rv_gift); mRecyclerView.setLayoutManager(new GridLayoutManager(mRecyclerView.getContext(), 4, GridLayoutManager.VERTICAL, false)); List<String> list = createList(); GiftAdapter adapter = new GiftAdapter(); adapter.setNewData(list); mRecyclerView.setAdapter(adapter); }
Example #25
Source File: MyDecorationTwo.java From MaterialDesignDemo with MIT License | 5 votes |
public boolean isLastRow(int itemPosition, RecyclerView parent) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { int spanCount = ((GridLayoutManager) layoutManager).getSpanCount(); int itemCount = parent.getAdapter().getItemCount(); if ((itemCount - itemPosition - 1) < spanCount) return true; } return false; }
Example #26
Source File: TeamInviteActivity.java From Android-Application-ZJB with Apache License 2.0 | 5 votes |
private void initRecyclerView(List<TeamMember> teamNumberList) { final GridLayoutManager mLayoutManager = new GridLayoutManager(this, 5); mAdapter = new TeamCreateAdapter(this, this); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); mAdapter.setData(mViewModel.listDeduplication(teamNumberList)); }
Example #27
Source File: DividerGridItemDecoration.java From NovelReader with MIT License | 5 votes |
private int getSpanCount(RecyclerView parent) { // 列数 int spanCount = -1; RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { spanCount = ((GridLayoutManager) layoutManager).getSpanCount(); } else if (layoutManager instanceof StaggeredGridLayoutManager) { spanCount = ((StaggeredGridLayoutManager) layoutManager) .getSpanCount(); } return spanCount; }
Example #28
Source File: SubjectTagsAdapter.java From fangzhuishushenqi with Apache License 2.0 | 5 votes |
@Override protected void onBindData(EasyRVHolder viewHolder, int position, BookListTags.DataBean item) { RecyclerView rvTagsItem = viewHolder.getView(R.id.rvTagsItem); rvTagsItem.setHasFixedSize(true); rvTagsItem.setLayoutManager(new GridLayoutManager(mContext, 4)); TagsItemAdapter adapter = new TagsItemAdapter(mContext, item.tags); rvTagsItem.setAdapter(adapter); viewHolder.setText(R.id.tvTagGroupName, item.name); }
Example #29
Source File: ItemDragHelperCallback.java From MicroReader with MIT License | 5 votes |
@Override public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { int dragFlags; RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager instanceof GridLayoutManager || manager instanceof StaggeredGridLayoutManager) { dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT; } else { dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; } // 如果想支持滑动(删除)操作, swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END int swipeFlags = 0; return makeMovementFlags(dragFlags, swipeFlags); }
Example #30
Source File: ShelfFragment.java From eBook with Apache License 2.0 | 5 votes |
private void initEvents(View v) { mContext = getActivity(); mBookList = BookLab.newInstance(mContext).getBookList(); RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.fragment_book_shelf_recycler_view); recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3)); recyclerView.setAdapter(new BookAdapter(mBookList)); }