All Projects → grzegorzojdana → SpacingItemDecoration

grzegorzojdana / SpacingItemDecoration

Licence: MIT license
ItemDecoration for RecyclerView that allows you to set spacing between and around list items in flexible way.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to SpacingItemDecoration

FlexItemDecoration
FlexItemDecoration, can customize the head, bottom, leftmost, rightmost dividing line, but also customize any one of the dividing lines and batch custom multiple dividing lines
Stars: ✭ 52 (-37.35%)
Mutual labels:  recyclerview, decoration, itemdecoration
StickyHeader
A simple lightweight sticky header ItemDecorator for RecyclerView
Stars: ✭ 108 (+30.12%)
Mutual labels:  recyclerview, itemdecoration
TimelineView
A customizable and easy-to-use Timeline View library for Android. Works as a RecyclerView decorator (ItemDecoration)
Stars: ✭ 169 (+103.61%)
Mutual labels:  recyclerview, itemdecoration
ItemDecorations
A dividers library for RecyclerView which use GridLayoutManager or LinearLayoutManager,when the RecyclerView used GridLayoutManager that supports Cross-Column feature.一款RecyclerView的分割线库,支持LinearLayoutManager和GridLayoutManager,当使用GridLayoutManager时支持跨行特性
Stars: ✭ 42 (-49.4%)
Mutual labels:  recyclerview, itemdecoration
Timeline
瀑布流式的时间轴
Stars: ✭ 2,028 (+2343.37%)
Mutual labels:  recyclerview, itemdecoration
swipeablerecyclerview
SwipeableRecyclerView provides a wrapper class SwipeItemTouchHelperCallback which can be used to add Dragging capability to your RecyclerView items. You can make use of DataBinding to bind it via XML.
Stars: ✭ 16 (-80.72%)
Mutual labels:  recyclerview
Recycling
A Library for make an easy and faster RecyclerView without adapter
Stars: ✭ 57 (-31.33%)
Mutual labels:  recyclerview
AdapterCommands
Drop in solution to animate RecyclerView's dataset changes by using command pattern
Stars: ✭ 74 (-10.84%)
Mutual labels:  recyclerview
SmartStickyHeader
A Custom Header View With Multiple Items to make selection from categories
Stars: ✭ 36 (-56.63%)
Mutual labels:  recyclerview
CSGO-Offset-Scanner
Java Based Cross-Platform CSGO Offset and Netvar Scanner
Stars: ✭ 28 (-66.27%)
Mutual labels:  offsets
My Android Garage
A quick reference guide for Android development.
Stars: ✭ 66 (-20.48%)
Mutual labels:  recyclerview
Pursuit-Core-Android
Pursuit Core Android
Stars: ✭ 45 (-45.78%)
Mutual labels:  recyclerview
TabSync
A lightweight synchronizer between Android's Tabs and Lists. Available on the View system and Jetpack Compose.
Stars: ✭ 98 (+18.07%)
Mutual labels:  recyclerview
Android-HeaderAndFooterRecyclerView
Let RecyclerView support add HeaderView and FooterView.
Stars: ✭ 36 (-56.63%)
Mutual labels:  recyclerview
ShimmerRecyclerView
A custom Shimmer RecyclerView which adopt to list / grid transition automatically and also supports multiple view types while shimmering.
Stars: ✭ 184 (+121.69%)
Mutual labels:  recyclerview
KRecyclerDsl
Kotlin Dsl for Android RecyclerView
Stars: ✭ 14 (-83.13%)
Mutual labels:  recyclerview
recyclerview-expandable
RecyclerView implementation of traex's ExpandableLayout
Stars: ✭ 70 (-15.66%)
Mutual labels:  recyclerview
ParkingDemo
Taipei City Parking Lot Information Query System Demo
Stars: ✭ 18 (-78.31%)
Mutual labels:  recyclerview
PrimeAdapter
PrimeAdapter makes working with RecyclerView easier.
Stars: ✭ 54 (-34.94%)
Mutual labels:  recyclerview
RecyclerViewExtensionsDemo
RecyclerView列表优化方案
Stars: ✭ 45 (-45.78%)
Mutual labels:  recyclerview

SpacingItemDecoration

release

ItemDecoration for RecyclerView that allows you to set spacing between and around list items in flexible way.

How to install

Add to your root build.gradle:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Add the dependency to your project's build.gradle:

dependencies {
    implementation 'com.github.grzegorzojdana:SpacingItemDecoration:1.1.0'
}

Since 1.1.0 version this library depends on androidx packages. If you have issues with manifest merger, you can stay with 1.0.1 version, which depends on old com.android.support packages.

How to use

Decoration with specified Spacing can be created and added to RecyclerView like this:

val spacingItemDecoration = SpacingItemDecoration(Spacing(
        // values in pixels are expected
        horizontal = resources.getDimensionPixelSize(R.dimen.spacing_horizontal),
        vertical = resources.dpToPx(16F).toInt(),
        edges = Rect(0, top, 0, 0)
))
list.addItemDecoration(spacingItemDecoration)

There are several spacing modifiers:

  • horizontal and vertical are the gaps between each two items.
  • item rectangle defines inset for each item (similar to item padding).
  • edges rectangle means offsets from the parent (RecyclerView) edges (similar to RecyclerView padding).

This library doesn't modify padding of any view, but calculates item offsets basing on given parameters.

Spacing can be easily modified:

spacingItemDecoration.spacing.apply {
    vertical = newVerticalSpacing
    edges.setEmpty()
}
// when modifying spacing properties, need to call invalidateSpacing()
spacingItemDecoration.invalidateSpacing()
// your's RecyclerView needs to know
list.invalidateItemDecorations()

If you change Spacing instance, you don't need to call invalidateSpacing.

val vItemSpacing = ...
spacingItemDecoration.spacing = Spacing(item = Rect(0, vItemSpacing, 0, vItemSpacing))
list.invalidateItemDecorations()

To see how different spacing values impact list layout, run sample app from this repo and play with configuration controls.

SpacingItemDecoration can also draw determined spacing, which is useful for debugging.

spacingItemDecoration.isSpacingDrawingEnabled = true
// you can change default colors used to mark specific spacing
spacingItemDecoration.drawingConfig = DrawingConfig(horizontalColor = Color.MAGENTA)
// if your decoration is already in use (items have been laid out), invalidate decor
list.invalidateItemDecorations()

Caveats

From the fact how this library works (providing item offsets with desired layout spacing without changing number of list rows and columns), list items will in result be laid out smaller than without this decoration, because some spacing is brought uniformly from each item's width and height.

This library works best if RecyclerView items have set one of the dimension to MATCH_PARENT (width if orientation is VERTICAL, and height if orientation is HORIZONTAL). Otherwise, you can see that when using GridLayoutManager the item.bottom or item.right spacing could not work.

StaggeredLayoutManager is not currently fully supported. For VERTICAL orientation, vertical spacing won't work, and edges.top and edges.bottom spacings will behave like item.top and item.bottom spacings. Similar, for HORIZONTAL orientation, horizontal spacing, edges.left and edges.right are broken. However, it is planned to be fixed in some future release.

Performance tips

If you use GridLayoutManager with list of huge number of items (thousands), you might would like to try this tips:

  • Set spacingItemDecoration.isGroupCountCacheEnabled to true. This will make determined group count be held by decoration implementation, but you will need to call invalidate() method each time the number of items or the properties of layout manager changes (orientation, span count, span size lookup object or items span size).
  • If you use non-default implementation of SpanSizeLookup but its getSpanSize(position) method always returns 1, you might want to set spacingItemDecoration.hintSpanSizeAlwaysOne to true. You may also consider enable span indices caching.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].