Android: Get Viewheight Programmatically
i am trying to get the height of a view and it keeps returning 0. this is what i have tried: View hourView = View.inflate(mContext, R.layout.calendar_hour_item,null); hourViewHeigh
Solution 1:
try
hourView.measure(hourView.getWidth(), hourView.getHeight());
hourView.getMeasuredHeight()
Solution 2:
In the first example it didn't worked because when you are querying them, the view still haven't performed the layout and measure steps. You only told the view how it would "behave" in the layout, but it still didn't calculated where to put each view.
(Similar question: How to get the width and height of an android.widget.ImageView?)
In the second example you posted, I don't think you added the view to the activity so the activity won't draw it hence, you will never read that log message. call setContentView
or addView
to some layout.
Solution 3:
You have provided the height as wrap_content
and you don't fill that content. Because of that it will display as 0.
Post a Comment for "Android: Get Viewheight Programmatically"