๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[Android] RecyclerView setHasFixedSize

developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#sethasfixedsize

 

RecyclerView  |  Android ๊ฐœ๋ฐœ์ž  |  Android Developers

RecyclerView open class RecyclerView : ViewGroup, ScrollingView, NestedScrollingChild2, NestedScrollingChild3 Known Direct Subclasses BaseGridView An abstract base class for vertically and horizontally scrolling lists. WearableRecyclerView Wearable speci

developer.android.com

androidx.recyclerview.widget.RecyclerView

open fun setHasFixedSize(hasFixedSize: Boolean) : Unit


hasFixedSize : Boolean - ์–ด๋Œ‘ํ„ฐ์˜ ๋ณ€ํ™”๊ฐ€ ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ์˜ ํฌ๊ธฐ์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค๋ฉด true, ์˜ํ–ฅ์„ ์ค€๋‹ค๋ฉด false


๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ์˜ ํฌ๊ธฐ๊ฐ€ ์–ด๋Œ‘ํ„ฐ์˜ ๋‚ด์šฉ์— ๋”ฐ๋ผ ์˜ํ–ฅ๋ฐ›์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์„ ๋ฏธ๋ฆฌ ์•Œ๋ฉด ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๋Š” ์—ฌ๋Ÿฌ ์ตœ์ ํ™”๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ์˜ ์ž์‹ ๋ทฐ๋‚˜ ์–ด๋Žํ„ฐ์˜ ๋‚ด์šฉ๋“ค(ํ•ญ๋ชฉ ๊ฐœ์ˆ˜ ์ œ์™ธํ•˜๊ณ )๊ณผ ์ƒ๊ด€์—†์ด ๋‹ค๋ฅธ ์š”์†Œ๋“ค(๋ถ€๋ชจ ๋ทฐ์˜ ํฌ๊ธฐ ๋“ฑ)์— ์˜ํ•ด์„œ๋Š” ํฌ๊ธฐ๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๊ฐ€ ์ด ๊ฒฝ์šฐ์— ํ•ด๋‹นํ•˜๋ฉด true๋ฅผ ์„ค์ •ํ•˜๋ผ. ๊ทธ๋Ÿฌ๋ฉด ์–ด๋Œ‘ํ„ฐ์˜ ๋‚ด์šฉ์ด ๋ณ€๊ฒฝ๋˜๋ฉด ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ๊ฐ€ ๋ ˆ์ด์•„์›ƒ ์ „์ฒด๋ฅผ ๋ฌดํšจํ™”ํ•ด ๋‹ค์‹œ ๊ทธ๋ฆฌ๋Š” ๊ฒƒ์„ ๋ง‰๋Š”๋‹ค.

 

  • ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ์˜ layout_height ๊ฐ’์ด match_parent ์ผ ๋•Œ > hasFixedSize(true)
  • ๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ์˜ layout_height ๊ฐ’์ด wrap_content ์ผ ๋•Œ > hasFixedSize(false)

๋ฆฌ์‚ฌ์ดํด๋Ÿฌ๋ทฐ ์‚ฌ์šฉ์‹œ์˜ ์ตœ์ ํ™”๋ฅผ ์œ„ํ•˜์—ฌ.