I want to have a fixed size block 120x180 dp that contains an image with the correct aspect ratio and a border drawn around it.
XML:
<android.support.constraint.ConstraintLayout android:layout_width="120dp" android:layout_height="180dp" app:layout_gravity="center"> <ImageView android:id="@+id/picture" android:layout_width="0dp" android:layout_height="0dp" android:background="@drawable/game_border" app:srcCompat="@drawable/pic_lion" android:scaleType="centerInside" />
Game_border Layout:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#55111111" /> <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" /> <corners android:radius="6dp" /> </shape> </item> </layer-list>
This scaleType works fine because it fills the entire interior of the tile and the background is not overestimated. But to demonstrate the wrong aspect ratio, I increased the maximum margin. See the figure below. I tried the remaining values, but they either drew the border or did not fill the full inside.
How can I use a slab that has a border around a part of the image with the correct aspect ratio? Image can be cut off. I think this method is called central culture. I found it in the Picasso library.

FitXY warps the image:

A hand-drawn image when I cropped the image while maintaining the aspect ratio. Sorry, it looks ugly, but generosity ends very soon.

Bjorn:

Rahul's answer has no bottom line

source share