An RecyclerView which places equal Space/Gap/Margin between RecyclerView Items. (Supporting LinearLayout, GridLayout, Rtl and Horizontal)
In you root build.gradle file, add JitPack to "repositories" block:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
and in your app module add this library to the dependencies block:
dependencies {
compile 'me.farahani.spaceitemdecoration:spaceitemdecoration:1.0'
}
and in your code:
val recyclerView = //...
val space = // in Px
val includeEdge = // false if you want no space between border items and recyclerView
recyclerView.addItemDecoration(SpaceItemDecoration(space, includeEdge))
All of code is in a single file of SpaceItemDecoration, feel free to copy/paste it in your code.
Short answer, NO! For more detailed answer continue reading...
Equal space between RV items is a common scenario and it could be achieved simply by setting margin=space-value/2 for items layouts and padding=space-value/2 for RV. I wanted to reuse item layouts and more importantly, I don't like that! :) And what if you don't want that space between items and RV itself?
So I thought, no problem, I could write a custom ItemDecoration
, set outRect.\*=space/2
for
all items and if items are at border of the list, border sides should have outRect.\*=space
.
Not only it was harder that what it looked first (supporting combination of orientation and layout direction),
but also result was wrong! See below:
It's because items size is fixed and calculated by RV. So in this way, border items get 3/2space and become smaller than middle items. It forced me to grab a pen and paper and find a formula which in addition to implementation, took more times than it should (for a task as simple as setting equal space). So I make it a library and I'm hopeful it saves some people some hours.
An item span index is not deterministic in SGL, for example an item could be at left most position in second row, but actually be last item. SGL.LayoutParams provide a spanIndex value which could be all I needed, but when scrolling, items could be shuffled after the spanIndex is set and so its unreliable.
🚕 find Iran's cities taxi fares for android-نرخ کرایه تاکسی های ایران در اندروید
Experimental project for learning computer graphics using vulkan API and c++.
An alternative YouTube front end, for Android. [WIP]
a sample clean architecture project with jetpack compose
Android Toast For RTL Applications
Flutter_Todo_app 📝
NMock is an application that you can use to mock your trips with fake locations. This application uses Neshan SDK and Neshan API for Map and location information.
Sample Android Clean MVVM architecture ( Retrofit + Okhttp + Moshi + Glide + Room + Navigation Component + Coroutines + Flow + DataStore + ViewModel + Hilt + Data binding )