I’ve got a tiled pan-n-zoom component that uses several FrameLayouts to position image tiles (that scale), markers (that move, but don’t scale) and controls (which neither move nor scale). It works fine.
Markers are positioned in a FrameLayout with topMargin and leftMargin. So far so good.
When a marker is touched, I need to open a little popup, at the same position as the marker that was touched but offset by the dimensions of the popup. That’s to say that if the popup is 100 pixels wide and 50 pixels tall, and the marker touched was at 800 x and 1100 y, the popup should be at 750 x (postion of marker minus half the width of the popup) and 1050 y (position of the marker minus the full height of the popup). The effect is like a tooltip – a little nub points down at the marker, etc.
The popup dimensions are flexible, based on the text to be displayed, and need to be calculated.
Obviously the dimensions aren’t available until after layout happens. What’s the best way to get these dimensions and react accordingly?
(should mention that a RelativeLayout is not an option)
TYIA.
/EDIT
looks like I can get the dimensions of the children in onMeasure and onLayout, but re-applying a new layout in one of these handlers would create an infinite loop – setting a flag to catch just the first pass did not work. i guess the updated question would be “now that I know where I can get the information, how should I react and position it?”
the answer is to manage positioning by override onLayout of the containing ViewGroup, rather than the View itself.
E.g.,
(note that the above example specifically is untested, but i’ve tested the premise and it works)