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

  • Home
  • SEARCH
  • 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 8646227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:45:08+00:00 2026-06-12T12:45:08+00:00

I need to resize an ImageView such that it fits to the screen, maintains

  • 0

I need to resize an ImageView such that it fits to the screen, maintains the same aspect ratio. The following conditions hold:

  • Images are a fixed width (size of the width of screen)
  • Images are downloaded from the Internet, i.e. size can only be determined later
  • Aspect ratio for each image will vary; some are tall, some are square, some are flat
  • ImageView’s height needs to change, either bigger or smaller based on the aspect ratio of the
  • Excess height is cropped, can’t have a lot of empty space like it is by default.

For example, a tiny 50×50 image on a 400 px width screen would scale the image up to 400×400 px. A 800×200 image would scale to 400×100.

I’ve looked at most of the other threads, and many proposed solutions like simply changing adjustViewBounds and scaleType will only scale down an image, and not scale it up.

  • 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-06-12T12:45:09+00:00Added an answer on June 12, 2026 at 12:45 pm
    ImageView mImageView; // This is the ImageView to change
    
    // Use this in onWindowFocusChanged so that the ImageView is fully loaded, or the dimensions will end up 0.
    public void onWindowFocusChanged(boolean hasFocus) 
    {
        super.onWindowFocusChanged(hasFocus);
    
        // Abstracting out the process where you get the image from the internet
        Bitmap loadedImage = getImageFromInternet (url);
    
        // Gets the width you want it to be
        intendedWidth = mImageView.getWidth();
    
        // Gets the downloaded image dimensions
        int originalWidth = loadedImage.getWidth();
        int originalHeight = loadedImage.getHeight();
    
        // Calculates the new dimensions
        float scale = (float) intendedWidth / originalWidth;
        int newHeight = (int) Math.round(originalHeight * scale);
    
        // Resizes mImageView. Change "FrameLayout" to whatever layout mImageView is located in.
        mImageView.setLayoutParams(new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT));
        mImageView.getLayoutParams().width = intendedWidth;
        mImageView.getLayoutParams().height = newHeight;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to resize/crop images in different resolutions for Android App. I know, that
I need to resize my image proportionately without changing aspect ratio.I have the code
I need to resize and crop to exactly 60x80px from various size and aspect
I need to resize images in php using GD to a fixed size but
I need to resize images and resample them so they don't end up all
I've got a situation where I need to resize a large number of images.
In my application I need to resize the bitmap to imageview size. I tried
On image you can see screen, that I need to implement http://cs301703.userapi.com/u20441799/154158276/z_aadbf840.jpg I'm confused
I need to resize the same image size in uitableviewcell. I using the same
So I need to resize my sprites with respect to the phones screen size,

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.