일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- kotlin
- hilt
- Navigation
- CoordinatorLayout
- ViewModel
- View
- HTTP
- onMeasure
- activity
- 안드로이드
- BOJ
- sqlite
- lifecycle
- LiveData
- DataBinding
- 알고리즘
- 코틀린
- Behavior
- Coroutine
- CollapsingToolbarLayout
- AppBarLayout
- room
- notification
- onLayout
- recyclerview
- Algorithm
- 백준
- 알림
- Android
- CustomView
- Today
- Total
목록ItemDecoration (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: ..