Note that there are some explanatory texts on larger screens.

plurals
  1. POScale a view and its layered subviews relatively
    primarykey
    data
    text
    <p>(This is somewhat a follow-up on <a href="https://stackoverflow.com/questions/3744854">Android: How do you scale multiple views together?</a>)</p> <p>My task is to port an iPhone / iPad app on Android that consists of a simple image view on which animations are layered on top in absolute positions. While this sounds rather easy on iOS where you only have to target a few possible screen sizes, it gets rather messy with Android.</p> <p>My current setup is this: A RelativeLayout in which I place my main (background) image on left = 0, top = 0 and multiple ViewFlipper instances used as "animation containers" that are positioned relatively to the upper left corner of the parent layout instance.</p> <p>This approach has two basic problems:</p> <ol> <li><p>The positioned "animations" are mis-positioned as soon as the actual size of the layout does not match the size of the main background image.</p></li> <li><p>The positioned "animations" are also mis-sized, because since they usually have "enough space" around themselves, Android doesn't scale them to fit into the RelativeLayout (nor would it scale them relatively to the original background.</p></li> </ol> <p>Since the animations itself must be interactive, its not a solution to place and position all of the animations on a transparent layer that has the same size as the main (background) image, as they'd overlap each other and only the upper-most would be interactive at all.</p> <p>I thought of different solutions:</p> <ol> <li><p>To get the the scale factor of the main image, I could retrieve its <code>measuredWidth</code> and <code>measuredHeight</code> and set this into relation of the original <code>width</code> and <code>height</code> of the view. Then I'd use this scale factor for custom positioning and eventually custom scaling. But, apparently the <code>measuredWidth/-Height</code> properties are only set during the <a href="http://developer.android.com/reference/android/view/View.html#onMeasure%28int,%20int%29" rel="nofollow noreferrer">onMeasure()</a> call and this is called after the component tree was built, so I don't know if this solution is feasible at all.</p></li> <li><p>Implement my own layout manager and scale / position the views accordingly. I had a look at the implementation of <code>RelativeLayout</code>, but have to admit that the <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.4_r1/android/widget/RelativeLayout.java#299" rel="nofollow noreferrer">onMeasure()</a> method scares me a bit.</p></li> </ol> <p>What would you do in my case? Is there anything I haven't yet taken into account?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload