Development issue/problem:

I have a square image (although this problem also applies to rectangular images). I want to display the image as large as possible and stretch it as much as possible to fill it for my parents without changing the proportions. The image is smaller than ImageView. The problem is that I can’t stretch the image to the height and width of the ImageView.

This is my XML format file:

I have used many combinations of fill_parent, wrap_content with different kinds of scaling: fitCenter, fitStart, fitEnd, centerInside, and they all draw images in the right format, but none of them scale the images and ImageView itself, so either the TextViews are completely off-screen, or the blank spaces within ImageView, or the images are not scaled, or the images are cropped.

I can’t find the right combination.

How can I solve this problem?

Solution 1:

This one:

android: layout_height=wrap_content

the size of the valley and the countries should be adapted to the new valley size. If this is not the case on your device, send the shield, which you use and test on the device in question.

Solution No 2:

Indicate this code:

Further information on the training of children can be found in this article yesterday.


You see the picture in perspective, but don’t forget it.

ImageView fills parent’s width OR height, but maintains aspect ratio –

Equalize the bild (maintaining the bild proportions) so that both dimensions (width and height) of the bild are equal or larger than the corresponding width of the body (in addition to the fold material). Das Bild will then zentriert if

ImageView fills parent’s width OR height, but maintains aspect ratio –

Scale the image (while maintaining the proportions of the image) so that both dimensions (width and height) of the image are equal to or smaller than the size of the corresponding view (minus the filler material).

ImageView fills parent’s width OR height, but maintains aspect ratio –

ImageView fills parent’s width OR height, but maintains aspect ratio –

ImageView fills parent’s width OR height, but maintains aspect ratio –

ImageView fills parent’s width OR height, but maintains aspect ratio –

ImageView fills parent’s width OR height, but maintains aspect ratio –

Image matrix scaling when drawing

ImageView fills parent’s width OR height, but maintains aspect ratio –

read more here new article

Solution 3:

This xml code will work! If you indicate that the width of your applications always matches the width of the window, android:adjustViewBounds=true will adjust the height to the image standard.

Solution 4:

Use this code together with the layout display options as the contents of the envelope.

android: adjustViewBounds=true

I hope it works.

Solution No 5:

I had the same problem, android:adjustViewBounds does not do its job and has a padding at the top of the image. I had a relative format with match_parental values for width and height:

I changed the relative layout to a linear layout with wrap_content values for width and height, and now it works well:

Solution No 6:

Have you tried setting it up for software math? I think it works very well if you calculate the height of the TextView and adjust the height and width of the image accordingly.

private void adjustImageView()
//Get display dimensions
DisplayMetrics metrics = new DisplayMetrics() ;
getWindowManager().getDefaultDisplay().getMetrics(Metrics) ;

// TextView name
TextView name = (TextView) findViewById(;
name.setText(Your name is here);
name.measure(0, 0) ;

//Name TextView Height
int nomH = nom.getMeasuredHeight() ;

//TextView name2
TextView name2 = (TextView) findViewById(;
name2.setText(Your name2 text goes here);
name2.measure(0, 0) ;

//name2 TextView height
int name2H = name2.getMeasuredHeight() ;

//Original image
Bitmap imageOriginal = BitmapFactory.decodeResource(getResources(), R.drawable.image) ;

//width/height ratio of your image
float imageOriginalWidthHeightRatio = (float) imageOriginal.getWidth() / (float) imageOriginal.getHeight() ;

// Calculate the new image width and height to
int imageToShowHeight = metrics.heightPixels – nameeH – name2H ;
int imageToShowWidth = (int) (imageOriginalWidthHeightRatio * imageToShowHeight) ;

//Adjust the width and height of the image if it is larger than the
screen as (imageToShowWidth > metrics.widthPixels)
imageToShowWidth = metrics.widthPixels;
imageToShowHeight = (int) (imageToShowWidth / imageOriginalWidthHeightRatio);

//Create a new image to display with the new dimensions
Bitmap imageToShow = Bitmap.createScaledBitmap(imageOriginal, imageToShowWidth, imageToShowHeight, true) ;

//Display the image in ImageView
ImageView image = (ImageView) findViewById(;

Solution No 7:

Set Sie android: layout_height=wrap_content in picture display.
In order to erect a shield, the width of the circumference and the height of the shield is set proportionally to the proportions, you can see how a shield is viewed from a high angle.

Glide.with(context).load(url).asBitmap().in(new SimpleTarget() {
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation)) {

// Establish a bilge to support the seating position, and the width of the bilge shall be set to the width of the bilge company.
int width = imageView.getMeasuredWidth();
int diw = resource.getWidth();
as (diw > 0) {
int height = 0;
height = width * resource.getHeight() / diw;
resource = Bitmap.createScaledBitmap(resource, width, height, false);

I hoffe, das hilft.

Fell Glück!

object-fit: cover not working,css background image size to fit div,caniuse object-fit,object-fit polyfill,how to fit image in div responsive,video object-fit center,android resize bitmap keep aspect ratio,android:scaletype,resize image drawable android studio,android imageview fit width crop height,android resize imageview based on screen size,android resize bitmap without losing quality,layout_constraintdimensionratio,android view aspect ratio,android imageview aspect ratio,aspect ratio-imageview android github,android get aspect ratio programmatically,how to get aspect ratio of image in android,android imageview 16:9,android scale image programmatically,android imageview stretch to fill width,swiftui view aspect ratio,swiftui view fill parent,swiftui crop image to square,xcode content mode,swiftui clipped,swiftui relative width,imageview fill aspect ratio,constraintlayout width match height,imageview scaletype,imageview android maintain aspect ratio,imageview set width height,maintain aspect ratio imageview,imageview aspect ratio kotlin,set width and height of imageview android

You May Also Like

How to remove Anatova ransomware from Windows 10 PCs

You can use the Windows Safe Mode to stop the Anatova ransom…

How to Implement draggable map like uber android, Update with change location –

Development issue/problem: How to implement a card through drag and drop, such…

How to Set the Date and Time on Raspberry Pi (Desktop & Lite) –

For most people, the Raspberry Pi operating system (whichever one you use)…

Something happened and your PIN isn’t available [SOLVED]

Another pin problem you may encounter is the pin of Windows Hello,…