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

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

[Android][View] getWidth(), getHeight() ์™€ measureWidth(), measuredHeight()

์ถœ์ฒ˜

https://yongheon.tistory.com/entry/Android-getMeasuredHeight-%EC%99%80-getHeight

 

[Android] getMeasuredHeight ์™€ getHeight

Android์˜ View ํด๋ž˜์Šค์™€ View ํด๋ž˜์Šค๋ฅผ ์ƒ์† ๋ฐ›๋Š” ๋ชจ๋“  ํด๋ž˜์Šค๋Š” ํ™”๋ฉด์— ๋ณด์—ฌ์ง€๊ธฐ ์œ„ํ•ด์„œ๋Š” ํฌ๊ฒŒ ๋‘ ๋‹จ๊ณ„๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๊ฑฐ์น˜๊ฒŒ ๋œ๋‹ค. 1. Measuring: View์˜ ํฌ๊ธฐ๋ฅผ ๊ณ„์‚ฐ. Width์™€ height ๊ฐ’์„ ๊ตฌํ•œ๋‹ค. 2. Layouting:

yongheon.tistory.com

https://stackoverflow.com/a/8664581

 

What is the difference between getWidth/Height() and getMeasuredWidth/Height() in Android SDK?

The Android Documentation says that there is two sizes for a view, the measured dimensions and the drawing dimensions. The measured dimension is the one computed in the measure pass (the onMeasure ...

stackoverflow.com

ChatGPT

https://velog.io/@haero_kim/Android-View-%EC%9D%98-%ED%95%9C-%ED%8F%89%EC%83%9D-%EC%82%B4%ED%8E%B4%EB%B3%B4%EA%B8%B0

 

[Android] View ์˜ ํ•œ ํ‰์ƒ ์‚ดํŽด๋ณด๊ธฐ

๋„ˆ๋ฌด ์•„๋ฆ„๋‹ค์šด ๋‹ค์šด ๋‹ค์šด ๋‹ค์šด View (์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค)

velog.io

 


measuredWidth(), measuredHeight()

๋ทฐ์˜ ์ธก์ •๋œ ๋„ˆ๋น„, ๋†’์ด๋ฅผ ๋ฐ˜ํ™˜ํ™˜๋‹ค. ์ด ๊ฐ’์€ ๋ ˆ์ด์•„์›ƒ์— ๋ฐฐ์น˜๋˜๊ธฐ ์ „์˜ ๋„ˆ๋น„์™€ ๋†’์ด๋กœ, ๋ถ€๋ชจ ๋ทฐ๊ฐ€ ์ž์‹ ๋ทฐ๋ฅผ ์ธก์ •ํ•˜๋ฉด์„œ ๊ณ„์‚ฐํ•œ ํฌ๊ธฐ์ด๋‹ค.

์‚ฌ์šฉ ๊ฐ€๋Šฅ ์‹œ์ 

onMeasure()๋ฅผ ํ†ตํ•ด ์ธก์ •๋œ ์ดํ›„๋ถ€ํ„ฐ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ onLayout() ์ด์ „์ด๋ผ๋„ ์ธก์ •์ด ์™„๋ฃŒ๋˜๋ฉด ๊ฐ’์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

์‚ฌ์šฉ ๋ชฉ์ 

์ฃผ๋กœ ๋ทฐ๊ฐ€ ๋ฐฐ์น˜๋˜๊ธฐ ์ „์— ๋ทฐ์˜ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ •ํ•˜๊ฑฐ๋‚˜, ์ธก์ •๋œ ํฌ๊ธฐ์— ๋”ฐ๋ผ ๋™์ ์œผ๋กœ ๋ ˆ์ด์•„์›ƒ์„ ์กฐ์ •ํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.

์˜ˆ : ์ž์‹ ๋ทฐ์˜ ํฌ๊ธฐ๋ฅผ ๋ฏธ๋ฆฌ ๊ณ„์‚ฐํ•˜๊ณ  ๋ถ€๋ชจ ๋ทฐ์˜ ๋ ˆ์ด์•„์›ƒ์„ ๊ฒฐ์ •ํ•˜๊ธฐ

 

getWidth(), getHeight()

๋ทฐ์˜ ์‹ค์ œ ๋„ˆ๋น„, ๋†’์ด ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ํ™”๋ฉด์— ๋ฐฐ์น˜๋œ ํ›„์˜ ์ตœ์ข… ํฌ๊ธฐ๋กœ, ๋ ˆ์ด์•„์›ƒ์ด ๋๋‚œ ์‹œ์ ์— ํ˜ธ์ถœํ•ด์•ผ ์œ ํšจํ•œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

์‚ฌ์šฉ ๊ฐ€๋Šฅ ์‹œ์ 

onLayout() ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๋ฐฐ์น˜๋œ ํ›„๋ถ€ํ„ฐ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. ์ด๋Š” ๋ทฐ๊ฐ€ ํ™”๋ฉด์— ๋ฐฐ์น˜๋˜์–ด ์ตœ์ข… ํฌ๊ธฐ๊ฐ€ ๊ฒฐ์ •๋œ ์ดํ›„์— ์œ ํšจํ•œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

์‚ฌ์šฉ ๋ชฉ์ 

์ฃผ๋กœ ๋ทฐ๊ฐ€ ๋ฐฐ์น˜๋œ ํ›„ ์ตœ์ • ํฌ๊ธฐ๋ฅผ ํ•„์š”๋กœ ํ•˜๋Š” ์ž‘์—…์—์„œ ์‚ฌ์šฉ๋œ๋‹ค. 

์˜ˆ : ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ ๋ทฐ๊ฐ€ ํ™”๋ฉด์—์„œ ์ฐจ์ง€ํ•˜๋Š” ์ •ํ™•ํ•œ ํฌ๊ธฐ๋ฅผ ํ•„์š”๋กœ ํ•˜๋Š” ๊ฒฝ์šฐ

 

 

View์˜ ๋ผ์ดํ”„์‚ฌ์ดํด

์ถœ์ฒ˜ : https://www.geeksforgeeks.org/how-to-create-your-own-custom-view-in-android-with-kotlin/