Kotlin (2) 썸네일형 리스트형 [안드로이드/kotlin] ViewTreeObserver로 View의 크기 구하기 View에는 width, height 혹은 measuredWidth, measuredHeight 함수가 존재한다. 하지만 이걸 onCreate() 에서 호출하게 되면 0을 리턴하게 된다. onCreate 시점에는 View가 아직 그려지기 전 단계이기 때문이다. 뷰의 크기를 구하기 위해서는 'ViewTreeObserver'를 사용하면 되는데, 이름 그대로 ViewTree에 대한 옵저버(감시 혹은 관찰)라고 보면 된다. A view tree observer is used to register listeners that can be notified of global changes in the view tree. 공식 문서에도 설명이 상세하게 기재되어 있다. 말 그대로 View Tree가 변경될 때 변경사항을 .. [안드로이드/Kotlin] RecyclerView를 이용한 GridView 생성하기 (GridLayoutManager) 안드로이드에는 격자 형태로 아이템을 보여주는 GridView 라는 위젯이 존재한다. 하지만 GridView를 사용하는 대신 RecyclerView에 GridLayoutManager 를 설정하여 사용할 수 있다. val gridLayoutManager = GridLayoutManager(this, 3) mBinding.recyclerItem.layoutManager = gridLayoutManager mBinding.recyclerItem.adapter = RecyclerAdapter() GridLayoutManager 를 생성할 때 파라미터로 context 와 한 줄에 표시해줄 아이템 수인 spanCount 를 입력하면 된다. GridLayoutManager(this, 3) -> 한 줄에 3개의 아이템을.. 이전 1 다음