Java Code Examples for androidx.recyclerview.widget.RecyclerView#setPadding()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#setPadding() .
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: TransitionMusicLibraryDemoFragment.java From material-components-android with Apache License 2.0 | 6 votes |
private RecyclerView createRecyclerView(boolean listTypeGrid) { Context context = requireContext(); RecyclerView recyclerView = new RecyclerView(context); recyclerView.setLayoutParams( new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); int verticalPadding = context.getResources().getDimensionPixelSize(R.dimen.album_list_padding_vertical); recyclerView.setPadding(0, verticalPadding, 0, verticalPadding); recyclerView.setClipToPadding(false); if (listTypeGrid) { recyclerView.setLayoutManager(new GridLayoutManager(context, GRID_SPAN_COUNT)); } else { recyclerView.setLayoutManager(new LinearLayoutManager(context)); recyclerView.addItemDecoration( new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); } return recyclerView; }
Example 2
Source File: AdvancedListFragment.java From YcShareElement with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRecyclerView = (RecyclerView) view; mRecyclerView.setBackgroundColor(0xFF323232); mAdapter = new AdvancedListAdapter(); mRecyclerView.setAdapter(mAdapter); int divider = getResources().getDimensionPixelSize(R.dimen.divider); mRecyclerView.setPadding(divider/2,divider/2,divider/2,divider/2); RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(),2); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.addItemDecoration(new SpaceItemDecoration(divider)); initCells(); }
Example 3
Source File: CustomUltimateRecyclerview.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
@Override protected void initViews() { //super.initViews(); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.custom_recycler_view_layout, this); mRecyclerView = (RecyclerView) view.findViewById(R.id.ultimate_list); mSwipeRefreshLayout = null; if (mRecyclerView != null) { mRecyclerView.setClipToPadding(mClipToPadding); if (mPadding != -1.1f) { mRecyclerView.setPadding(mPadding, mPadding, mPadding, mPadding); } else { mRecyclerView.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom); } } defaultFloatingActionButton = (FloatingActionButton) view.findViewById(R.id.defaultFloatingActionButton); setDefaultScrollListener(); mEmpty = (ViewStub) view.findViewById(R.id.emptyview); mFloatingButtonViewStub = (ViewStub) view.findViewById(R.id.floatingActionViewStub); mEmpty.setLayoutResource(mEmptyId); mFloatingButtonViewStub.setLayoutResource(mFloatingButtonId); if (mEmptyId != 0) mEmptyView = mEmpty.inflate(); mEmpty.setVisibility(View.GONE); if (mFloatingButtonId != 0) { mFloatingButtonView = mFloatingButtonViewStub.inflate(); mFloatingButtonView.setVisibility(View.VISIBLE); } }
Example 4
Source File: UltimateRecyclerView.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
protected void initViews() { inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.ultimate_recycler_view_layout, this); mRecyclerView = (RecyclerView) view.findViewById(R.id.ultimate_list); mSwipeRefreshLayout = (VerticalSwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout); setScrollbars(); mSwipeRefreshLayout.setEnabled(false); if (mRecyclerView != null) { mRecyclerView.setClipToPadding(mClipToPadding); if (mPadding != -1.1f) { mRecyclerView.setPadding(mPadding, mPadding, mPadding, mPadding); } else { mRecyclerView.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom); } } defaultFloatingActionButton = (FloatingActionButton) view.findViewById(R.id.defaultFloatingActionButton); setDefaultScrollListener(); /** * empty view setup */ mEmpty = (ViewStub) view.findViewById(R.id.emptyview); if (mEmptyId != 0) { mEmpty.setLayoutResource(mEmptyId); mEmptyView = mEmpty.inflate(); mEmpty.setVisibility(View.GONE); } /** * floating button setup */ mFloatingButtonViewStub = (ViewStub) view.findViewById(R.id.floatingActionViewStub); mFloatingButtonViewStub.setLayoutResource(mFloatingButtonId); }
Example 5
Source File: PreferenceFragment.java From Jockey with Apache License 2.0 | 5 votes |
@Override public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { RecyclerView view = super.onCreateRecyclerView(inflater, parent, savedInstanceState); view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background)); int padding = (int) getResources().getDimension(R.dimen.global_padding); view.setPadding(padding, 0, padding, 0); view.addItemDecoration(new BackgroundDecoration(android.R.id.title)); view.addItemDecoration(new DividerDecoration(getContext(), android.R.id.title)); return view; }
Example 6
Source File: AutoColumnGridLayoutManager.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Removes the padding previously added to the <code>recyclerView</code> * for the edge spacing. If no padding was previously added, then this * has no affect * * @param recyclerView The RecyclerView to remove the padding from */ protected void resetRecyclerPadding(@NonNull RecyclerView recyclerView) { recyclerView.setPadding( recyclerView.getPaddingLeft() - edgeSpacing, recyclerView.getPaddingTop(), recyclerView.getPaddingRight() - edgeSpacing, recyclerView.getPaddingBottom() ); }
Example 7
Source File: AbsLibraryPagerRecyclerViewCustomGridSizeFragment.java From Phonograph with GNU General Public License v3.0 | 5 votes |
protected void applyRecyclerViewPaddingForLayoutRes(@NonNull RecyclerView recyclerView, @LayoutRes int res) { int padding; if (res == R.layout.item_grid) { padding = (int) (getResources().getDisplayMetrics().density * 2); } else { padding = 0; } recyclerView.setPadding(padding, padding, padding, padding); }
Example 8
Source File: NavigationFragment.java From AndroidPreferenceActivity with Apache License 2.0 | 5 votes |
@NonNull @Override public final RecyclerView onCreateRecyclerView(final LayoutInflater inflater, final ViewGroup parent, final Bundle savedInstanceState) { RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent, savedInstanceState); recyclerView.setClipToPadding(false); int paddingTop = getActivity().getResources().getDimensionPixelSize(R.dimen.list_view_padding_top); recyclerView.setPadding(recyclerView.getPaddingLeft(), paddingTop, recyclerView.getPaddingRight(), recyclerView.getPaddingBottom()); return recyclerView; }
Example 9
Source File: GridMarginsItemDecoration.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
private void setParentPadding(RecyclerView parent, @Px int padding, Rect insets) { parent.setPadding( padding + insets.left, padding, padding + insets.right, padding + insets.bottom ); parent.setClipToPadding(false); }
Example 10
Source File: GridMarginsDecoration.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
public GridMarginsDecoration(@Px float marginsVertical, @Px float marginsHorizontal, RecyclerView recyclerView) { this.marginsVertical = marginsVertical; this.marginsHorizontal = marginsHorizontal; recyclerView.setClipToPadding(false); recyclerView.setPadding( (int) marginsHorizontal / 2, (int) marginsVertical / 2, (int) marginsHorizontal / 2, (int) marginsVertical / 2 ); }
Example 11
Source File: BoxBrowseFolderGridFragment.java From box-android-browse-sdk with Apache License 2.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (parent.getPaddingLeft() != halfSpace) { parent.setPadding(halfSpace, halfSpace, halfSpace, halfSpace); parent.setClipToPadding(false); } outRect.top = halfSpace; outRect.bottom = halfSpace; outRect.left = halfSpace; outRect.right = halfSpace; }
Example 12
Source File: AbsLibraryPagerRecyclerViewCustomGridSizeFragment.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
protected void applyRecyclerViewPaddingForLayoutRes(@NonNull RecyclerView recyclerView, @LayoutRes int res) { int padding; if (res == R.layout.item_grid) { padding = (int) (getResources().getDisplayMetrics().density * 2); } else { padding = 0; } recyclerView.setPadding(padding, padding, padding, padding); }
Example 13
Source File: MenuBottomSheetDialog.java From revolution-irc with GNU General Public License v3.0 | 5 votes |
public MenuBottomSheetDialog(@NonNull Context context) { super(context); RecyclerView content = new RecyclerView(context); content.setLayoutManager(new LinearLayoutManager(context)); content.setAdapter(new ItemAdapter()); int verticalPadding = content.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_menu_vertical_margin); content.setPadding(0, verticalPadding, 0, verticalPadding); setContentView(content); content.setBackgroundColor(StyledAttributesHelper.getColor(context, R.attr.colorBackgroundFloating, 0)); }
Example 14
Source File: VerticalStepperView.java From MaterialStepperView with MIT License | 5 votes |
private void prepareListView(Context context) { mListView = new RecyclerView(context); mAdapter = new ItemAdapter(); mListView.setClipToPadding(false); mListView.setPadding(0, getResources().getDimensionPixelSize(R.dimen.stepper_margin_top), 0, 0); mListView.addItemDecoration(new VerticalSpaceItemDecoration( getResources().getDimensionPixelSize(R.dimen.vertical_stepper_item_space_height))); mListView.setLayoutManager(new LinearLayoutManager(context)); mListView.setAdapter(mAdapter); addView(mListView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); }
Example 15
Source File: AbsLibraryPagerRecyclerViewCustomGridSizeFragment.java From Music-Player with GNU General Public License v3.0 | 5 votes |
protected void applyRecyclerViewPaddingForLayoutRes(@NonNull RecyclerView recyclerView, @LayoutRes int res) { int padding; if (res == R.layout.item_grid) { padding = (int) (getResources().getDisplayMetrics().density * 2); } else { padding = 0; } recyclerView.setPadding(padding, padding, padding, padding); }
Example 16
Source File: GalleryAdapter.java From EhViewer with Apache License 2.0 | 4 votes |
private void adjustPaddings() { RecyclerView recyclerView = mRecyclerView; recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop() + mPaddingTopSB, recyclerView.getPaddingRight(), recyclerView.getPaddingBottom()); }
Example 17
Source File: FollowingItemDecoration.java From Mysplash with GNU Lesser General Public License v3.0 | 4 votes |
private void setParentPadding(RecyclerView parent, Rect insets) { parent.setPadding(insets.left, 0, insets.right, insets.bottom); parent.setClipToPadding(false); }
Example 18
Source File: AutoColumnGridLayoutManager.java From RecyclerExt with Apache License 2.0 | 4 votes |
/** * Calculates and adds the amount of spacing that needs to be between each * column, row, and the edges of the RecyclerView. This pays attention to * the value from {@link #setSpacingMethod(SpacingMethod)} * * @param recyclerView The RecyclerView to use for determining the amount of space that needs to be added * @param gridItemWidth The requested width for the items * @param columnCount The number of columns to display */ protected void updateSpacing(@NonNull RecyclerView recyclerView, int gridItemWidth, int columnCount) { //Sets the decoration for the calculated spacing if (spacerDecoration == null) { spacerDecoration = new SpacerDecoration(); spacerDecoration.setAllowedEdgeSpacing(SpacerDecoration.EDGE_SPACING_LEFT | SpacerDecoration.EDGE_SPACING_RIGHT); recyclerView.addItemDecoration(spacerDecoration); } edgeSpacing = minColumnSpacingEdge; int separatorSpacing = minColumnSpacingSeparator / 2; //Calculates the edge spacing requirements int padding = recyclerView.getPaddingLeft() + recyclerView.getPaddingRight(); int usableWidth = recyclerView.getWidth() - padding; int separatorCount = columnCount -1; int spacerCount = 2 * columnCount; int freeSpace = usableWidth - (gridItemWidth * columnCount); int extraSpace = freeSpace - (2 * minColumnSpacingEdge) - (separatorCount * minColumnSpacingSeparator); //If we can add spacing, then we need to calculate how much and where to add it if (extraSpace >= spacerCount) { if (spacingMethod == SpacingMethod.ALL) { int totalMinEdges = minColumnSpacingEdge * 2; int totalMinSeparators = separatorCount * minColumnSpacingSeparator; //If the totalMinSpace is 0, then the percentage is edge count / separators + edges int totalMinSpace = totalMinEdges + totalMinSeparators; double edgeSpacePercentage = totalMinSpace == 0 ? (2 / (2 + separatorCount)) : (double)totalMinEdges / (double)totalMinSpace; int totalSeparatorSpace = (int)((1d - edgeSpacePercentage) * freeSpace); separatorSpacing = spacerCount == 0 ? 0 : totalSeparatorSpace / spacerCount; edgeSpacing = ((freeSpace - totalSeparatorSpace) / 2) + separatorSpacing; } else if (spacingMethod == SpacingMethod.EDGES) { edgeSpacing = (freeSpace - (separatorSpacing * spacerCount)) / 2; } else { //SEPARATOR separatorSpacing = spacerCount == 0 ? 0 : freeSpace / spacerCount; } edgeSpacing -= separatorSpacing; } //Updates the spacing using the decoration and padding recyclerView.setPadding( recyclerView.getPaddingLeft() + edgeSpacing, recyclerView.getPaddingTop(), recyclerView.getPaddingRight() + edgeSpacing, recyclerView.getPaddingBottom() ); spacerDecoration.update(separatorSpacing, matchSpacing ? separatorSpacing : rowSpacing / 2); }
Example 19
Source File: MainActivity.java From ScrollingPagerIndicator with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int screenWidth = getScreenWidth(); // Setup ViewPager with indicator ViewPager pager = findViewById(R.id.pager); DemoPagerAdapter pagerAdapter = new DemoPagerAdapter(8); pager.setAdapter(pagerAdapter); ScrollingPagerIndicator pagerIndicator = findViewById(R.id.pager_indicator); pagerIndicator.attachToPager(pager); // Setup ViewPager2 with indicator ViewPager2 pager2 = findViewById(R.id.pager2); DemoRecyclerViewAdapter pagerAdapter2 = new DemoRecyclerViewAdapter(8, ViewGroup.LayoutParams.MATCH_PARENT); pager2.setAdapter(pagerAdapter2); ScrollingPagerIndicator pagerIndicator2 = findViewById(R.id.pager_indicator2); pagerIndicator2.attachToPager(pager2); // Setup RecyclerView with indicator // One page will occupy 1/3 of screen width RecyclerView recyclerView = findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); DemoRecyclerViewAdapter recyclerAdapter = new DemoRecyclerViewAdapter(8, screenWidth / 3); recyclerView.setAdapter(recyclerAdapter); recyclerView.setPadding(screenWidth / 3, 0, screenWidth / 3, 0); ScrollingPagerIndicator recyclerIndicator = findViewById(R.id.recycler_indicator); // Consider page in the middle current recyclerIndicator.attachToRecyclerView(recyclerView); SnapHelper snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(recyclerView); // Some controls NumberPicker pageCountPicker = findViewById(R.id.page_number_picker); pageCountPicker.setMaxValue(99); pageCountPicker.setMinValue(0); pageCountPicker.setValue(pagerAdapter.getCount()); NumberPicker visibleDotCountPicker = findViewById(R.id.visible_dot_number_picker); visibleDotCountPicker.setMinValue(3); visibleDotCountPicker.setMaxValue(11); visibleDotCountPicker.setValue(pagerIndicator.getVisibleDotCount()); visibleDotCountPicker.setOnValueChangedListener((picker, oldVal, newVal) -> { if (newVal % 2 == 0) { Toast.makeText(this, "Visible dot count must be odd number", Toast.LENGTH_SHORT).show(); return; } pagerIndicator.setVisibleDotCount(newVal); recyclerIndicator.setVisibleDotCount(newVal); }); pageCountPicker.setOnValueChangedListener((picker, oldVal, newVal) -> { if (pager.getCurrentItem() >= newVal - 1) { pager.setCurrentItem(newVal - 1, false); } pagerAdapter.setCount(newVal); recyclerAdapter.setCount(newVal); }); }
Example 20
Source File: GalleryAdapter.java From MHViewer with Apache License 2.0 | 4 votes |
private void adjustPaddings() { RecyclerView recyclerView = mRecyclerView; recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop() + mPaddingTopSB, recyclerView.getPaddingRight(), recyclerView.getPaddingBottom()); }