λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

빈 ꡬ멍 μ±„μš°κΈ°

[Android] LayoutInflater inflate ν•  λ•Œ viewGroup 지정 μ•ˆν•΄μ„œ λ‚˜μ˜¨ 이슈

λ¦¬μ‚¬μ΄ν΄λŸ¬λ·°μ˜ μ•„μ΄ν…œ μ‚¬μ΄μ¦ˆκ°€ μ΄μƒν–ˆλ‹€.

 

문제 상황

 

각 μ•„μ΄ν…œ λ ˆμ΄μ•„μ›ƒμ€ ConstraintLayout μ•ˆμ— κ΅¬μ„±λ˜μ–΄ μžˆμ—ˆλ‹€. μ΅œμƒμœ„ λ ˆμ΄μ•„μ›ƒμ˜ android:layout_width="match_parent" κ°€ λ¨Ήνžˆμ§€ μ•Šμ•„μ„œ λ§κ°€μ§€λŠ” κ²ƒμœΌλ‘œ μΆ”μΈ‘ν–ˆλ‹€. ν…μŠ€νŠΈλ§Œ λ°›λŠ” μ•„μ΄ν…œ, 썸넀일도 λ°›λŠ” μ•„μ΄ν…œ 이 두 가지 νƒ€μž…μ˜ 뷰홀더가 μžˆλŠ”λ° μ™œ 썸넀일 λ°›λŠ” μ•„μ΄ν…œλ§Œ μ΄λŸ¬λŠ” 건지 κ³ λ―Ό.

 

닡을 찾음.

 

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : ViewHolder {
	val inflater = LayoutInflater.from(parent.context)
    return when(viewType) {
    	VIEW_TEXT -> TextHolder(
        	ItemTxtBinding.inflate(inflater, parent, false)
        )
        VIEW_THUMBNAIL -> ThumnailHolder(
        	ItemThmbnlBinding.inflate(inflater) // <--문제 원인 발견
        )
    }
}

 

LayoutInflater에 κ΄€ν•΄ μ‚΄νŽ΄λ³΄κ³  κ°€κΈ°.

https://medium.com/vingle-tech-blog/android-layoutinflater-b6e44c265408

 

μ•ˆλ“œλ‘œμ΄λ“œ LayoutInflater μ‚¬μš©λ²•

LayoutInflaterλ₯Ό μ‚¬μš©ν•˜λŠ” 방법과, λΉ„λ™κΈ°μ μœΌλ‘œ LayoutInflaterλ₯Ό μ‚¬μš© ν•˜λŠ” 방법

medium.com

 

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : ViewHolder {
	val inflater = LayoutInflater.from(parent.context)
    return when(viewType) {
    	VIEW_TEXT -> TextHolder(
        	ItemTxtBinding.inflate(inflater, parent, false)
        )
        VIEW_THUMBNAIL -> ThumnailHolder(
        	ItemThmbnlBinding.inflate(inflater, parent, false) // <--문제 ν•΄κ²°
        )
    }
}

 

문제 ν•΄κ²°