Home Why won't my ImageView scale to fill the layout as much as the width permits?

# Why won't my ImageView scale to fill the layout as much as the width permits?

K_7
1#
K_7 Published in 2017-12-07 21:33:35Z
 What I want is for the ImageView to scale with the same ratio to fill the layout without being cropped. Since the width is going to match first, effectively, this means scaling until the width is maximized. My code is: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display); ImageView img = findViewById(R.id.displayImg); img.setImageBitmap(bmp); // bmp is a public static Bitmap set by another class img.setRotation(90); img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); }  My layout is:   As per Android ImageView ScaleType: A Visual Guide CENTER_INSIDE should Scale the image uniformly (maintain the image’s aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). The black image is what I'm currently, and I've drawn what I believe I should be seeing instead (as you can tell, I'm the modern-day Michelangelo).
DroiDev
2#
 wrap_content if the reason why.... change that to fill_parent or match_parent. Take a look at this: https://developer.android.com/reference/android/widget/ImageView.ScaleType.html CENTER_INSIDE Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). If the ratio of your image is off, it wont stretch. Java imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);  XML android:scaleType="fitCenter"  side note: fillXY might be better.
 You may acheive your desired result by making the dimensions of the ImageView match to the parent layout and apply fitCenter as a scaleType so it fills the view without losing aspect ratio:  
 I think you use wrong value. Try android:scaleType="fitXY" on xml   You don't need set again scaleType on activity. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display); ImageView img = findViewById(R.id.displayImg); img.setImageBitmap(bmp); // bmp is a public static Bitmap set by another class img.setRotation(90); //img.setScaleType(ImageView.ScaleType.ImageView.ScaleType.FIT_XY); You don't need this }