Primary/Android
Fragment에서 View의 크기를 알고 싶을 때
해스끼
2021. 5. 22. 21:30
한줄요약: ``onCreateView()``에서 ``binding.root.post``를 호출하고, 그 안에서 ``measuredHeight``/``measuredWidth``에 접근할 수 있다.
private var _binding: FragmentTestBinding? = null
private val binding
get() = _binding!!
override fun onCreateView() {
_binding = FragmentTestBinding.inflate(...)
binding.root.post {
val size = root.measuredHeight
// ...
}
}
Android get layout height and width in a fragment
I am working on a fragment and I want to get the dimension of a layout contained in the xml fragment layout. When I try the code RelativeLayout myLayout = view.findViewById(R.id.myLayout); myLayout.
stackoverflow.com