I want to have fixed size box 120x180 dp that contains a picture with correct aspect ratio and a border painted 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
setting works fine because it fill complete tile inner and background is not overriden. But to demonstrate incorrect aspect ratio I have increased top margin. See picture below. I tried remaining values but they either paint over the border or do not fill complete inner part.
How can I have the tile that has the border around a part of the picture with the right aspect ratio? The picture can be cut. I think that this technique is called center crop. I found it in the Picasso library.
FitXY deforms picture:
Manually painted picture when I cropped picture while preserving aspect ratio. Sorry, it looks ugly but bounty ends very soon.
Bjorn's answer:
Rahul answer does not have bottom border