Skip to content

Commit a8b10dd

Browse files
author
tamunobelemamiebaka-ogan
committed
Add custom span size for items makeing items in positions divisible by 3
1 parent f4f9986 commit a8b10dd

File tree

9 files changed

+35
-41
lines changed

9 files changed

+35
-41
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
100 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
204 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

.idea/workspace.xml

Lines changed: 26 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/raywenderlich/android/creatures/ui/AllFragment.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ class AllFragment : Fragment() {
6363

6464
fragmentAllBinding.creatureRecyclerView.apply {
6565
adapter = creatureAdapter
66-
layoutManager = GridLayoutManager(context, 2,
66+
val gridLayoutManager = GridLayoutManager(context, 2,
6767
GridLayoutManager.VERTICAL, false)
68+
gridLayoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
69+
override fun getSpanSize(position: Int): Int {
70+
return if ((position + 1) % 3 == 0) 2 else 1
71+
}
72+
73+
}
74+
layoutManager = gridLayoutManager
6875
}
6976
creatureAdapter.submitList(CreatureStore.getCreatures())
7077

app/src/main/java/com/raywenderlich/android/creatures/ui/CreatureCardViewHolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class CreatureCardViewHolder(
1919
RecyclerView.ViewHolder(creatureItemCreatureCardBinding.root) {
2020

2121
fun bind(creature: Creature, clickListener: (creature: Creature) -> Unit){
22-
creatureItemCreatureCardBinding.creature = creature
2322
creatureItemCreatureCardBinding.apply {
23+
this.creature = creature
2424
root.apply {
2525
setOnClickListener {
2626
clickListener(creature)

0 commit comments

Comments
 (0)