androidx.recyclerview.widget.GridLayoutManager Java Examples
The following examples show how to use
androidx.recyclerview.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: SearchViewModel.java From Jockey with Apache License 2.0 | 6 votes |
@Bindable public RecyclerView.LayoutManager getLayoutManager() { mColumnCount = ViewUtils.getNumberOfGridColumns(getContext(), R.dimen.grid_width); GridLayoutManager layoutManager = new GridLayoutManager(getContext(), mColumnCount); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (getAdapter().getItemViewType(position) == mAlbumSection.getTypeId()) { return 1; } else { return mColumnCount; } } }); return layoutManager; }
Example #2
Source File: FragmentEndlessScrolling.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
@Override protected GridLayoutManager createNewGridLayoutManager() { GridLayoutManager gridLayoutManager = new SmoothScrollGridLayoutManager(getActivity(), mColumnCount); gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { // NOTE: If you use simple integers to identify the ViewType, // here, you should use them and not Layout integers switch (mAdapter.getItemViewType(position)) { case R.layout.recycler_scrollable_expandable_item: case R.layout.recycler_scrollable_header_item: case R.layout.recycler_scrollable_footer_item: case R.layout.recycler_scrollable_layout_item: case R.layout.recycler_scrollable_uls_item: case R.layout.progress_item: return mColumnCount; default: return 1; } } }); return gridLayoutManager; }
Example #3
Source File: DividerGridItemDecoration.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.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 #4
Source File: SwipeToDismissActivity.java From RecyclerViewHelper with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.liner_layout: mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); break; case R.id.grid_layout: mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2)); break; } mDataList.clear(); getData(); mRecyclerView.setAdapter(mSwipeToDismissWrapper); return super.onOptionsItemSelected(item); }
Example #5
Source File: GridLayoutInfo.java From litho with Apache License 2.0 | 6 votes |
@Override public int approximateRangeSize( int firstMeasuredItemWidth, int firstMeasuredItemHeight, int recyclerMeasuredWidth, int recyclerMeasuredHeight) { final int spanCount = mGridLayoutManager.getSpanCount(); switch (mGridLayoutManager.getOrientation()) { case GridLayoutManager.HORIZONTAL: final int colCount = (int) Math.ceil((double) recyclerMeasuredWidth / (double) firstMeasuredItemWidth); return colCount * spanCount; default: final int rowCount = (int) Math.ceil((double) recyclerMeasuredHeight / (double) firstMeasuredItemHeight); return rowCount * spanCount; } }
Example #6
Source File: BrickItemTouchHelperCallbackTest.java From brickkit-android with Apache License 2.0 | 6 votes |
@Before public void setup() { brickSize = mock(BrickSize.class); brick = mock(BaseBrick.class); when(brick.getSpanSize()).thenReturn(brickSize); targetBrick = mock(BaseBrick.class); dataManager = mock(BrickDataManager.class); when(dataManager.getDragAndDrop()).thenReturn(false); when(dataManager.getSwipeToDismiss()).thenReturn(false); when(dataManager.brickAtPosition(anyInt())).thenReturn(brick, targetBrick); when(dataManager.getMaxSpanCount()).thenReturn(MAX_SPANS); callback = new BrickItemTouchHelperCallback(dataManager); viewHolder = mock(RecyclerView.ViewHolder.class); target = mock(RecyclerView.ViewHolder.class); recyclerView = mock(RecyclerView.class); when(recyclerView.getLayoutManager()).thenReturn(mock(GridLayoutManager.class)); }
Example #7
Source File: ItemMoveCallback.java From RecyclerViewHelper with Apache License 2.0 | 6 votes |
@Override public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { // Set movement flags based on the layout manager. int swipeFlags = 0; int dragFlags; if (recyclerView.getLayoutManager() instanceof GridLayoutManager) { dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT; } else { if (mIsFreedom) { dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT; } else { dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; } } return makeMovementFlags(dragFlags, swipeFlags); }
Example #8
Source File: SuperDividerItemDecorationActivity.java From RecyclerViewHelper with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { SuperDividerItemDecoration dividerItemDecoration = null; switch (item.getItemId()) { case R.id.liner_layout: LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(linearLayoutManager); dividerItemDecoration = new SuperDividerItemDecoration(this, linearLayoutManager); break; case R.id.grid_layout: GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 5, RecyclerView.VERTICAL, false); mRecyclerView.setLayoutManager(gridLayoutManager); dividerItemDecoration = new SuperDividerItemDecoration(this, gridLayoutManager); break; } if (dividerItemDecoration != null) { dividerItemDecoration.setDrawable(getResources().getDrawable(R.drawable.custom_bg_divider)); mRecyclerView.addItemDecoration(dividerItemDecoration); mRecyclerView.removeItemDecorationAt(0); } mDataList.clear(); getData(); mRecyclerView.setAdapter(mDividerAdapter); return super.onOptionsItemSelected(item); }
Example #9
Source File: RecyclerViewEmptyViewSupport.java From Kore with Apache License 2.0 | 6 votes |
@SuppressWarnings("ResourceType") public RecyclerViewEmptyViewSupport(Context context, @Nullable AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setSaveEnabled(true); if (attrs != null) { int[] attrsArray = { android.R.attr.columnWidth, android.R.attr.columnCount }; TypedArray array = context.obtainStyledAttributes( attrs, attrsArray); columnWidth = array.getDimensionPixelSize(0, -1); columnCount = array.getInteger(1, AUTO_FIT); array.recycle(); } gridLayoutManager = new GridLayoutManager(getContext(), 1); setLayoutManager(gridLayoutManager); }
Example #10
Source File: GridSpacingItemDecoration.java From a with GNU General Public License v3.0 | 6 votes |
@Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { if (parent.getLayoutManager() != null) { if (parent.getLayoutManager() instanceof LinearLayoutManager && !(parent.getLayoutManager() instanceof GridLayoutManager)) { if (((LinearLayoutManager) parent.getLayoutManager()).getOrientation() == LinearLayoutManager.HORIZONTAL) { outRect.set(space, 0, space, 0); } else { outRect.set(0, space, 0, space); } } else { outRect.set(space, space, space, space); } } }
Example #11
Source File: DynamicRecyclerView.java From dynamiclistview with MIT License | 6 votes |
@Override public boolean reachedListTop() { if (getChildCount() > 0) { LayoutManager lm = getLayoutManager(); int firstVisiblePosition = -1; int firstVisibleViewY = -1; if (lm instanceof LinearLayoutManager) { firstVisiblePosition = ((LinearLayoutManager) lm).findFirstVisibleItemPosition(); } else if (lm instanceof GridLayoutManager) { firstVisiblePosition = ((LinearLayoutManager) lm).findFirstVisibleItemPosition(); } firstVisibleViewY = getChildAt(0).getTop(); return firstVisiblePosition == 0 && firstVisibleViewY == getPaddingTop(); } else return false; }
Example #12
Source File: MultiItemQuickUseActivity.java From BaseRecyclerViewAdapterHelper with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_multiple_item_use); setTitle("BaseMultiItemQuickAdapter"); setBackBtn(); RecyclerView mRecyclerView = findViewById(R.id.rv_list); final List<QuickMultipleEntity> data = DataServer.getMultipleItemData(); final MultipleItemQuickAdapter multipleItemAdapter = new MultipleItemQuickAdapter(data); final GridLayoutManager manager = new GridLayoutManager(this, 4); mRecyclerView.setLayoutManager(manager); multipleItemAdapter.setGridSpanSizeLookup(new GridSpanSizeLookup() { @Override public int getSpanSize(GridLayoutManager gridLayoutManager, int viewType, int position) { return data.get(position).getSpanSize(); } }); mRecyclerView.setAdapter(multipleItemAdapter); }
Example #13
Source File: ShareDialog.java From AndroidProject with Apache License 2.0 | 6 votes |
public Builder(Context context) { super(context); setContentView(R.layout.dialog_share); final List<ShareBean> data = new ArrayList<>(); data.add(new ShareBean(getDrawable(R.drawable.ic_share_wechat), getString(R.string.share_platform_wechat), Platform.WECHAT)); data.add(new ShareBean(getDrawable(R.drawable.ic_share_moment), getString(R.string.share_platform_moment), Platform.CIRCLE)); data.add(new ShareBean(getDrawable(R.drawable.ic_share_qq), getString(R.string.share_platform_qq), Platform.QQ)); data.add(new ShareBean(getDrawable(R.drawable.ic_share_qzone), getString(R.string.share_platform_qzone), Platform.QZONE)); data.add(new ShareBean(getDrawable(R.drawable.ic_share_link), getString(R.string.share_platform_link), null)); mAdapter = new ShareAdapter(context); mAdapter.setData(data); mAdapter.setOnItemClickListener(this); RecyclerView recyclerView = findViewById(R.id.rv_share_list); recyclerView.setLayoutManager(new GridLayoutManager(context, data.size())); recyclerView.setAdapter(mAdapter); mData = new UmengShare.ShareData(context); }
Example #14
Source File: SimpleItem.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
@Override public void scrollAnimators(@NonNull List<Animator> animators, int position, boolean isForward) { if (mAdapter.getRecyclerView().getLayoutManager() instanceof GridLayoutManager || mAdapter.getRecyclerView().getLayoutManager() instanceof StaggeredGridLayoutManager) { if (position % 2 != 0) AnimatorHelper.slideInFromRightAnimator(animators, itemView, mAdapter.getRecyclerView(), 0.5f); else AnimatorHelper.slideInFromLeftAnimator(animators, itemView, mAdapter.getRecyclerView(), 0.5f); } else { //Linear layout if (mAdapter.isSelected(position)) AnimatorHelper.slideInFromRightAnimator(animators, itemView, mAdapter.getRecyclerView(), 0.5f); else AnimatorHelper.slideInFromLeftAnimator(animators, itemView, mAdapter.getRecyclerView(), 0.5f); } }
Example #15
Source File: PostItemsAdapter.java From mimi-reader with Apache License 2.0 | 6 votes |
public void setLayoutManager(RecyclerView.LayoutManager manager) { layoutManager = manager; if (layoutManager instanceof GridLayoutManager) { managerType = ManagerType.GRID; ((GridLayoutManager) layoutManager).setSpanSizeLookup(gridSpanSizeLookup); } else if (layoutManager instanceof LinearLayoutManager) { managerType = ManagerType.LIST; } else if (layoutManager instanceof StaggeredGridLayoutManager) { managerType = ManagerType.STAGGERED_GRID; ((StaggeredGridLayoutManager) layoutManager).setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS); } else { managerType = ManagerType.OTHER; } Log.d(LOG_TAG, "Set manager type: value=" + managerType.name()); }
Example #16
Source File: PreferenceSectionAdapter.java From Status with Apache License 2.0 | 6 votes |
@Override public void onBindViewHolder(ViewHolder holder, int position) { holder.title.setText(sections.get(position).getName(context)); ArrayList<BasePreferenceData> items = getItems(sections.get(position)); PreferenceAdapter adapter = adapters.get(position); adapter.setItems(items); holder.recycler.setNestedScrollingEnabled(false); holder.recycler.setLayoutManager(new GridLayoutManager(context, 1)); holder.recycler.setAdapter(adapter); if (items.size() > 0) holder.v.setVisibility(View.VISIBLE); else holder.v.setVisibility(View.GONE); holder.v.setAlpha(0); holder.v.animate().alpha(1).setDuration(500).start(); }
Example #17
Source File: NetworkSettingsActivity.java From green_android with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_networksettings); getSupportActionBar().hide(); mProxySection = UI.find(this, R.id.proxySection); mSwitchTor = UI.find(this, R.id.switchEnableTor); mSocks5Host = UI.find(this, R.id.socks5Host); mSocks5Port = UI.find(this, R.id.socks5Port); mSwitchProxy = UI.find(this, R.id.switchEnableProxySettings); final RecyclerView recyclerView = UI.find(this, R.id.networksRecyclerView); recyclerView.setLayoutManager(new GridLayoutManager(this, 1)); final View closeButton = UI.find(this, R.id.close_network_settings); closeButton.setOnClickListener(this::onCloseClick); mSwitchProxy.setOnCheckedChangeListener(this::onProxyChange); mSwitchTor.setOnCheckedChangeListener(this::onTorChange); final Button selectButton = UI.find(this, R.id.selectNetworkButton); selectButton.setOnClickListener(this::onClick); selectButton.setText(R.string.id_save); }
Example #18
Source File: GridMarginsItemDecoration.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
public GridMarginsItemDecoration(RecyclerView recyclerView, int gridMargins, int singleSpanMargins, int gridCardRadius, int singleSpanCardRadius) { this.gridMargins = gridMargins; this.singleSpanMargins = singleSpanMargins; this.gridCardRadius = gridCardRadius; this.singleSpanCardRadius = singleSpanCardRadius; RecyclerView.LayoutManager layoutManager = getLayoutManager(recyclerView); if (layoutManager instanceof StaggeredGridLayoutManager) { singleSpan = ((StaggeredGridLayoutManager) layoutManager).getSpanCount() == 1; } else if (layoutManager instanceof GridLayoutManager) { singleSpan = ((GridLayoutManager) layoutManager).getSpanCount() == 1; } else if (layoutManager instanceof LinearLayoutManager) { // linear layout manager. singleSpan = true; } else if (MysplashApplication.isDebug(recyclerView.getContext())) { throw new RuntimeException("Null layout manager."); } else { singleSpan = false; } setParentPadding( recyclerView, (singleSpan ? singleSpanMargins : gridMargins) / 2, getWindowInset(recyclerView) ); }
Example #19
Source File: FragmentEndlessScrolling.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
@Override public void onPrepareOptionsMenu(Menu menu) { Log.v(TAG, "onPrepareOptionsMenu called!"); MenuItem gridMenuItem = menu.findItem(R.id.action_list_type); if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) { gridMenuItem.setIcon(R.drawable.ic_view_agenda_white_24dp); gridMenuItem.setTitle(R.string.linear_layout); } else { gridMenuItem.setIcon(R.drawable.ic_view_grid_white_24dp); gridMenuItem.setTitle(R.string.grid_layout); } MenuItem endlessMenuItem = menu.findItem(R.id.action_top_scrolling); endlessMenuItem.setChecked(mAdapter.isTopEndless()); }
Example #20
Source File: DividerGridItemDecorationUtils.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
private boolean isLastColumn(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 #21
Source File: BrickDataManagerTest.java From brickkit-android with Apache License 2.0 | 6 votes |
@Before public void setup() { if (Looper.myLooper() == null) { Looper.prepare(); } Context context = InstrumentationRegistry.getTargetContext(); manager = new BrickDataManager(MAX_SPANS); View parentView = mock(View.class); manager.setRecyclerView(context, new RecyclerView(context), GridLayoutManager.VERTICAL, false, parentView); brickTestHelper = new BrickTestHelper(context); for (int i = 0; i < STARTING_BRICKS; i++) { manager.addLast(brickTestHelper.generateBrick()); } footerBehavior = mock(StickyFooterBehavior.class); manager.addBehavior(footerBehavior); headerBehavior = mock(StickyHeaderBehavior.class); manager.addBehavior(headerBehavior); observer = new BrickTestHelper.TestAdapterDataObserver(); manager.getBrickRecyclerAdapter().registerAdapterDataObserver(observer); }
Example #22
Source File: GridDividerDecoration.java From pandora with Apache License 2.0 | 6 votes |
private boolean isLastRow(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { int lines = childCount % spanCount == 0 ? childCount / spanCount : childCount / spanCount + 1; return lines == pos / spanCount + 1; } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { childCount = childCount - childCount % spanCount; if (pos >= childCount) return true; } else { if ((pos + 1) % spanCount == 0) { return true; } } } return false; }
Example #23
Source File: GridMentions.java From Spyglass with Apache License 2.0 | 6 votes |
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid_mentions); recyclerView = findViewById(R.id.mentions_grid); recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); adapter = new PersonMentionAdapter(new ArrayList<Person>()); recyclerView.setAdapter(adapter); editor = findViewById(R.id.editor); editor.setTokenizer(new WordTokenizer(tokenizerConfig)); editor.setQueryTokenReceiver(this); editor.setSuggestionsVisibilityManager(this); editor.setHint(getResources().getString(R.string.type_person)); people = new Person.PersonLoader(getResources()); }
Example #24
Source File: LoadMoreActivity.java From RecyclerViewHelper with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.liner_layout: mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); break; case R.id.grid_layout: mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2)); break; } mDataList.clear(); getData(); mLoadMoreWrapper.setLoadState(mLoadMoreWrapper.LOADING_COMPLETE); mRecyclerView.setAdapter(mLoadMoreWrapper); return super.onOptionsItemSelected(item); }
Example #25
Source File: AbstractFragment.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_list_type) { if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) { mRecyclerView.setLayoutManager(createNewLinearLayoutManager()); item.setIcon(R.drawable.ic_view_grid_white_24dp); item.setTitle(R.string.grid_layout);//next click showNewLayoutInfo(item); } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) { mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager()); item.setIcon(R.drawable.ic_view_agenda_white_24dp); item.setTitle(R.string.linear_layout);//next click showNewLayoutInfo(item); } else { mRecyclerView.setLayoutManager(createNewGridLayoutManager()); item.setIcon(R.drawable.ic_dashboard_white_24dp); item.setTitle(R.string.staggered_layout);//next click showNewLayoutInfo(item); } } return super.onOptionsItemSelected(item); }
Example #26
Source File: FlexibleDividerDecoration.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * @param manager * @param position * @return */ protected int positionTotalSpanSize(GridLayoutManager manager, int position) { int totalSpanSize = 0; GridLayoutManager.SpanSizeLookup spanSizeLookup = manager.getSpanSizeLookup(); int spanCount = manager.getSpanCount(); int groupIndex = spanSizeLookup.getSpanGroupIndex(position, spanCount); for (int i = position; i >= 0; i--) { int thisGroupIndex = spanSizeLookup.getSpanGroupIndex(i, spanCount); if (thisGroupIndex == groupIndex) { totalSpanSize += spanSizeLookup.getSpanSize(i); } else { break; } } return totalSpanSize; }
Example #27
Source File: EmojiBSFragment.java From PhotoEditor with MIT License | 6 votes |
@SuppressLint("RestrictedApi") @Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); View contentView = View.inflate(getContext(), R.layout.fragment_bottom_sticker_emoji_dialog, null); dialog.setContentView(contentView); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams(); CoordinatorLayout.Behavior behavior = params.getBehavior(); if (behavior != null && behavior instanceof BottomSheetBehavior) { ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback); } ((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent)); RecyclerView rvEmoji = contentView.findViewById(R.id.rvEmoji); GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 5); rvEmoji.setLayoutManager(gridLayoutManager); EmojiAdapter emojiAdapter = new EmojiAdapter(); rvEmoji.setAdapter(emojiAdapter); }
Example #28
Source File: ExpandableAdapter.java From SwipeRecyclerView with Apache License 2.0 | 6 votes |
@Override public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { RecyclerView.LayoutManager lm = recyclerView.getLayoutManager(); if (lm instanceof GridLayoutManager) { final GridLayoutManager glm = (GridLayoutManager)lm; final GridLayoutManager.SpanSizeLookup originLookup = glm.getSpanSizeLookup(); glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (isParentItem(position)) return glm.getSpanCount(); if (originLookup != null) return originLookup.getSpanSize(position); return 1; } }); } }
Example #29
Source File: ColorViewAdapter.java From colorpicker with Apache License 2.0 | 6 votes |
public ViewHolder(View v) { super(v); //buttons settings colorItem = v.findViewById(R.id.color); colorItem.setTextColor(tickColor); colorItem.setBackgroundResource(buttonDrawable); colorItem.setOnClickListener(this); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) colorItem.getLayoutParams(); layoutParams.setMargins(marginButtonLeft, marginButtonTop, marginButtonRight, marginButtonBottom); if (buttonWidth != -1) layoutParams.width = buttonWidth; if (buttonHeight != -1) layoutParams.height = buttonHeight; //relative layout settings LinearLayout linearLayout = v.findViewById(R.id.linearLayout); GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) linearLayout.getLayoutParams(); lp.setMargins(marginLeft, marginTop, marginRight, marginBottom); }
Example #30
Source File: ViewAssistRecyclerViewLoadActivity.java From DevUtils with Apache License 2.0 | 6 votes |
@Override public void initValues() { super.initValues(); ViewGroup parent = (ViewGroup) vid_bvr_recy.getParent(); // 根布局处理 ViewHelper.get().setPadding(parent, 0); String url = "https://picsum.photos/id/%s/1080/1920"; List<String> lists = new ArrayList<>(); for (int i = 0; i < 20; i++) { lists.add(String.format(url, RandomUtils.getRandom(1, 1000))); } // 初始化布局管理器、适配器 vid_bvr_recy.setLayoutManager(new GridLayoutManager(this, 2)); vid_bvr_recy.setAdapter(new RecyclerLoadingAdapter(lists)); }