일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- hilt
- onMeasure
- room
- CoordinatorLayout
- LiveData
- 코틀린
- 알림
- 안드로이드
- Algorithm
- View
- ViewModel
- kotlin
- Android
- recyclerview
- notification
- 알고리즘
- Behavior
- lifecycle
- Coroutine
- CustomView
- sqlite
- AppBarLayout
- onLayout
- Navigation
- activity
- CollapsingToolbarLayout
- BOJ
- 백준
- HTTP
- DataBinding
- Today
- Total
목록여백 (2)
개발일지

StaggeredGridLayoutManager를 이용한 RecyclerView에서 ViewHolder에 Margin을 설정하면 배치가 이상해지는 오류가 발생했다. => gapStrategy를 설정하자 with(binding.recyclerView) { adapter = MovieAdapter() addItemDecoration(GridSpacingItemDecoration(2, 5.toDp())) layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL).apply { gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_NONE } }

ItemDecoration RecyclerView의 ViewHolder를 꾸미는 역할을 한다. ViewHolder간의 동일한 여백을 주거나, 구분선을 넣기, RecyclerView Background 이미지 주기 등 다양한 효과를 줄 수 있다. GridSpacingItemDecoration 여백을 주는 ItemDecoration이다. class GridSpacingItemDecoration(private val spanCount: Int, private val spacing: Int, private val includeEdge: Boolean = true) : RecyclerView.ItemDecoration() { override fun getItemOffsets(outRect: Rect, view: ..