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 7496517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:39:02+00:00 2026-05-29T18:39:02+00:00

Update: The multiple device screen dimensions is a red herring – the problem is

  • 0

Update:
The multiple device screen dimensions is a red herring – the problem is just that the image does not scale up properly to fill the screen – see comments on Ivan’s answer.

I have a layout file with one image:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/image"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop" />

Then I assign a drawable, which is small and must be scaled up:

setContentView(R.layout.image_story);
ImageView image = (ImageView)findViewById(R.id.image);
image.setImageDrawable(s.image);

Here is how it is rendered on two AVDs with different screen dimensions. These should be the same (detailed question at the bottom). Sorry for the large images.

with scaleType=centerCrop:


with centerInside


AVDs:


Edit:

With layout_height=”fill_parent” and scaleType=”centerInside”


I have a 2.1 AVD with the default values, so the screen is smaller, and this works exactly as expected- the image is scaled up to fill the width, and the view height is wrapped to the scaled height.

On my Droid Bionic with a longer screen, and on any AVD with the same screen dimensions, this doesn’t work- the image is scaled to fill the width, but the view is wrapped to the original pre-scale image height, so the top and bottom are cropped off.

I have no idea why the device screen aspect ratio would have an effect on this. I’ve tried countless combination of layout parameters and scale types trying to get this to work on the Bionic. Everything works exactly as expected on the smaller screen, and not on the larger. If I set the image height explicitly in dp, it works as expected, but I never know what the dimensions of the image (or screen) will be. Any suggestions?

  • 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-29T18:39:06+00:00Added an answer on May 29, 2026 at 6:39 pm

    That is a very good question indeed.

    Here’s the reason it’s behaving like that (from ImageView.onMeasure(int, int) [line 661]):

    // Try adjusting height to be proportional to width
    if (!done && resizeHeight) {
        int newHeight = (int)((widthSize - pleft - pright)
                / desiredAspect) + ptop + pbottom;
        if (newHeight <= heightSize) { // line 661
            heightSize = newHeight;
        } // line 663
    }
    

    What it does is it adjusts the height of the view only if the new height that is based on aspect ratio of the drawable and the adjusted width (in our case, that’s exact width of the parent view) is smaller than the adjusted height (which at this poin is just drawable’s native height plus padding in our case. Let me know if you want me to brake down this point further.)

    What I don’t get is why is there the restriction that new height must be smaller. It makes sense only if our heightSize is either EXACTLY or AT_MOST and has been set to the upper bound. In other cases it’s not necessary for it to be so.

    So actually instead of the whole piece 661 through 663 there should have been another call to

    heightSize = resolveAdjustedSize(newHeight, mMaxHeight, heightSpec);
    

    to make sure we only use the height restriction when it should be restricted (ie. we got AT_MOST restriction in heightSpec and the height value in heightSpec is smaller than the new height. EXACTLY can’t happen here unless we use variable width.)

    Maybe, I missed something there. Guys, whoever is reading this, please comment if you see any flaws in that, especially if you’re part of Android team at Google 🙂

    PS As a workaround, I can suggest you implement a custom ImageView and override onMeasure(int, int) to set the bounds to your exact aspect ratio. Let me know if you need help on the actual code.

    UPD I’m going to write out names to catch attention of smart android guys at Google (I’m hoping the guys have Google Alerts set up): Romain Guy, Roman Nurik, Reto Meier, please, take a look at this discussion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/ UPDATE person
I need write an update statement that used multiple tables to determine which rows
I am basically just trying to update multiple values in my table. What would
I'm trying to update multiple rows that all share the same field names. The
Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
How can I update multiple values in MySQL? This didn't work: UPDATE test SET
I have the following SQL statement where i'm trying to update multiple rows matching
How to do svn update of multiple files located across different directories ? For
Update : To clear up confusion: by multiple records I mean multiple individuals at
how to easily update php web application to multiple server ? i read about

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.