6

I've create a custom view based on LinearLayout and I need to calculate the layout width and height according to the parent view but each time I use ((View)this.getParent()).getMeasuredWidth() I got 0 - I guess that I called this function too early!

Any ideas to how accomplish this functionality?

KOTIOS
  • 11,177
  • 3
  • 39
  • 66
iSun
  • 1,714
  • 6
  • 28
  • 57

2 Answers2

1

in Kotlin you can use like this :

   val height = (parent as View).height
Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
-1

if your view parent have layout params "android:layout_width="wrapContent", you can not get the width.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268