Background
There are various XML attributes for ImageView to scale its contents and various layouts that allow you to place views and set their sizes.
However, I cannot figure out how to scale the image well in some cases.
An example of this is placing the ImageView at the bottom (for example, frameLayout), scaling its width as large as possible and preserving the aspect ratio (without cropping).
Problem
None of the combinations found work, including various ScaleType, adjustViewBounds, gravity, ...
ImageView seems to be missing some important ScaleType values.
What i tried
So far, the only solution that worked for me is to set the image at the bottom (using gravity in the lower and central horizontal) and use a code similar to this:
final ImageView logoBackgroundImageView = ...; final LayoutParams layoutParams = logoBackgroundImageView.getLayoutParams(); final Options bitmapOptions = ImageService.getBitmapOptions(getResources(), R.drawable.splash_logo); final int screenWidth = getResources().getDisplayMetrics().widthPixels; layoutParams.height = bitmapOptions.outHeight * screenWidth / bitmapOptions.outWidth; logoBackgroundImageView.setLayoutParams(layoutParams);
This usually works and does not need big changes to make it work when it is not in full screen, but I am wondering if there is an easier way.
Perhaps this will not work if the height is too high, so you can change it so that in case this happens, you will set the width to a smaller size so that everything fits the container.
Question
Is there a solution or library that fixes various problems with ImageView?
EDIT: here is an example image of what I'm trying to do, this time, within the vertical LinearLayout, which borders the ImageView in the middle between two other views:

As you can see, in some (or all?) Previews, the average image is aligned to the right, and does not remain in the middle (horizontally).
I want him to take all the space that he got and scale it (keeping the proportions), but still aligned to the bottom of the space that he has.
here is a sample XML of one combination that I tried:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF339AE2"> <View android:layout_width="match_parent" android:id="@+id/topView" android:layout_alignParentTop="true" android:layout_height="100dp" android:background="#FF00ff00" /> <FrameLayout android:layout_below="@+id/topView" android:layout_width="match_parent" android:layout_centerHorizontal="true" android:layout_above="@+id/bottomView" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:background="#FFffff00" android:layout_gravity="bottom|center_horizontal" android:src="@android:drawable/sym_def_app_icon" android:scaleType="fitEnd" android:layout_height="match_parent" /> </FrameLayout> <View android:background="#FFff0000" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:id="@+id/bottomView" android:layout_width="match_parent" android:layout_height="100dp"/> </RelativeLayout>
Note again that I tried several combinations, but none of them worked, so if you suggest changing something in XML, try it first. Also note that the above POC value (to make it easy to read).
By the way, the workaround that I suggested works in some (or most?) Cases, but not in all. You can notice this by simply turning the device. Perhaps there is a way to fix it or extend it from ImageView to provide an extra case.