I am new to Android. This should be the easiest thing in the world, but figuring it out is confusing: how do I get the dimensions of a view or layout?
The standard approach seems to be something like:
((LinearLayout) this.findViewById (R.id.MyLayout)) GetWidth () ;.
Except that it always returns zero, since I try to do this when the activity starts (onCreate) and the geometry is not set yet. I tried to include the sleeping places to give him the opportunity to customize the layout, except that he would not customize the layout until onCreate returned. So this is clearly not threaded .: P
I found a bunch of pages talking about overriding all kinds of different callback functions to make sure the layout loads when getWidth is called - but they all threw errors when I tried to put overrides in my activity, so I can assume that they were inverse calls to measure layouts and / or views. The problem is that I do not use custom view / layout classes - only standard ones. As far as I know, I can't just add an override.
Does anyone know what I should do? I spent something like 8 hours on this problem and received nothing. And thatβs what usually such a trivial thing to do in most development environments!
source share