Alternative to AbsoluteLayout

449 Views Asked by At

the question "What is a usefull alternative to AbsoluteLayout?" seems to be a question which is often asked, but never really answered. My situation is as follows:

I want to position Circles (for the sake of simplicity i used RadioButtons for testing) so that the distances between the circles are proportional on all possible display sizes.

Also i need to know the position of the circles to match onTouchEvent.

This seems fairly easy with AbsoluteLayout since i can get (at runtime) the defaultDisplay's width and height and so i can position Objects in an AbsoluteLayout relative to the display metrics.

Now I want to avoid AbsoluteLayout for obvious reasons, but RelativeLayout doesn't seem to be an alternative since - as far as i know - one can only say "put that object right next to that other object" or below or whatever. How to fix this?

2

There are 2 best solutions below

1
On BEST ANSWER

In my Opinion the best way to achieve your goal is to use the Canvas and draw everything yourself. In the Canvas you have the information of the screen at runtime and you have full control of the things to draw.

0
On

If you only need to draw your own shapes (and handle all normal touch events) and do not need other UI Widgets on the same view, then use Canvas.

If you do need Widgets on this view then your only option is AbsoluteLayout.