Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:42:59+00:00 2026-05-23T14:42:59+00:00

(This is somewhat a follow-up on Android: How do you scale multiple views together?

  • 0

(This is somewhat a follow-up on Android: How do you scale multiple views together?)

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.

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.

This approach has two basic problems:

  1. 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.

  2. 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.

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.

I thought of different solutions:

  1. To get the the scale factor of the main image, I could retrieve its measuredWidth and measuredHeight and set this into relation of the original width and height of the view. Then I’d use this scale factor for custom positioning and eventually custom scaling. But, apparently the measuredWidth/-Height properties are only set during the onMeasure() call and this is called after the component tree was built, so I don’t know if this solution is feasible at all.

  2. Implement my own layout manager and scale / position the views accordingly. I had a look at the implementation of RelativeLayout, but have to admit that the onMeasure() method scares me a bit.

What would you do in my case? Is there anything I haven’t yet taken into account?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:43:00+00:00Added an answer on May 23, 2026 at 2:43 pm

    Well, answering my own question – here is the way I resolved the issue:

    1. I placed the background image on the top of my ImageView with ImageView.setScaleType(ScaleType.FIT_START)
    2. I calculated the scale factor of my background image like so:
        WindowManager mgr = (WindowManager) context
                    .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics metrics = new DisplayMetrics();
        mgr.getDefaultDisplay().getMetrics(metrics);
        Drawable image = context.getResources().getDrawable(R.drawables.someImage);
        float scale = metrics.widthPixels / (float) image.getIntrinsicWidth();
    
    1. Finally, I used this scale in a custom ImageView class that loads the overlays to position and scale the view properly:
        public class OverlayImage extends ImageView
        {
            private int imgWidth, imgHeight;
            private final float scale;
    
            public OverlayImage(Context context, int xPos, int yPos, float scale)
            {
                super(context);
                this.scale = scale;
    
                LayoutParams animParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
                animParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                animParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                animParams.leftMargin = (int) (scale * xPos);
                animParams.topMargin = (int) (scale * yPos);
                setLayoutParams(animParams);
    
                Drawable dr = context.getResources().getDrawable(R.id.someImage);
                setBackgroundDrawable(dr);
                imgWidth = dr.getIntrinsicWidth();
                imgHeight = dr.getIntrinsicHeight();
            }
    
            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
            {
                setMeasuredDimension((int) (scale * imgWidth),
                        (int) (scale * imgHeight));
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This somewhat follows on from the question Saving application data to the ipad/iphone Really
This is somewhat of a follow-up to an answer here . I have a
This is somewhat of a follow-up question to this question . Suppose I have
I know that this is somewhat subjective, but I wonder if there is a
This is somewhat of a follow up to a question posted earlier last month.
This is somewhat a follow up to a previous question - but I've distilled
This is somewhat annoying. It appears that webkit (through chrome 13 canary) is having
EDIT: I've been convinced that this question is somewhat non-sensical. Thanks to those who
Consider this somewhat of a follow up to this question . Essentially, the C++
This is a somewhat of a follow up to this posting but with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.