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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:45:38+00:00 2026-05-26T23:45:38+00:00

I have an imageview which will have a fixed size: layout_width=100dip layout_height=50dip but the

  • 0

I have an imageview which will have a fixed size:

layout_width="100dip"
layout_height="50dip"

but the bitmap I want to place in there can be a variable width / height. I’d like to scale the bitmap (maintaining aspect ratio) to fit the 100dip,50dip space. After scaling up, I’d like to center it vertically, and left-align it.

Do any of the predefined imageview android:scaleType flags do that for us?

If not, is the only way to do this to modify the bitmap myself manually (create a canvas at 100dip, 50dip dip size, then place the bitmap in the canvas at the position I want after scaling it up)?

Thanks

  • 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-26T23:45:39+00:00Added an answer on May 26, 2026 at 11:45 pm

    You do not need to create a canvas, you can use the imageview’s setImageMatrix method instead. Like so:

    final Bitmap bitmap = ...;//your bitmap
    final int bitmapWidth = bitmap.getWidth();
    final int bitmapHeight = bitmap.getHeight();
    final float scaleRatio = Math.min(100f/bitmapWidth,50f/bitmapHeight);
    final float deltaX = (100 - bitmapWidth * scaleRatio)/2;
    final float deltaY = (50 - bitmapHeight * scaleRatio)/2;
    final Matrix matrix = new Matrix();
    matrix.postScale(scaleRatio,scaleRatio);
    matrix.postTranslate(deltaX,deltaY);
    imageView.setImageBitmap(bitmap);
    imageView.setImageMatrix(matrix);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ImageView which will display an image from the web. I used
I have a ImageView and draw some things on that view. Now I want
I have added an imageView of size 300*300 into the interface in my ipad
I have a listview which includes 2 textviews and 1 imageview. Now, the image
I have a gridview in which there are two elements in each of its
I have a UITableViewCell, it is scroll-disabled and with fixed sections and rows. There
I am making small bubble words game where there will be many bubble(Imageview) on
I have a pinch gesture recognizer attached to an imageview from which I use
I have created an app in which I want to use the touchbegan method.
I have an Imageview which is zoomed and rotated(I have used multitouch zooming ).

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.