I'm an Android newbie. This should be the easiest thing in the world, but figuring it out is driving me batty: how do I get the dimensions of a view or layout?
The standard approach seems to be something along the lines of:
((LinearLayout)this.findViewById(R.id.MyLayout)).getWidth();
Except that this always returns zero, since I'm trying to do this when the Activity starts up (onCreate) and the geometry isn't set yet. I tried putting in sleeps to give it a chance to set up the layout, except that it won't set up the layout until onCreate returns. So it's clearly not threaded. :P
I found a bunch of pages talking about overriding all sorts of different callback functions in order to be sure that the layout is loaded when you call getWidth -- but all of them threw errors when I tried to put the overrides in my Activity. So I can assume that they were callbacks for the layouts and/or views being measured. The problem with that is that I'm not using custom view/layout classes -- just the standard ones. So I can't just add an override, as far as I know.
Anyone know what I should do? I've spent something like 8 hours on this problem and gotten nowhere. And it's something that's normally such a trivial thing to do in most development environments!