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?

8
  • what error you are getting please post log cat Commented Dec 21, 2013 at 12:54
  • @Hardik I don't get any errors, I just get zero value instead of actual layout width and height! Commented Dec 21, 2013 at 12:55
  • stackoverflow.com/questions/5375631/… Commented Dec 21, 2013 at 12:56
  • try my answer and tell me Commented Dec 21, 2013 at 12:56
  • Are you doing this in onCreate()? Commented Dec 21, 2013 at 12:58

2 Answers 2

1

in Kotlin you can use like this :

 val height = (parent as View).height 
Sign up to request clarification or add additional context in comments.

Comments

-1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.