Bitmap scaling in layer format

I am trying to create a background drawing made from a gradient that fills the entire view and a left-gravity template that resizes to fit the vertical while maintaining its aspect ratio.

This is what I have:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/myGradient"/> <item> <bitmap android:src="@drawable/myPattern" android:gravity="left" /> </item> </layer-list> 

Both pins are VectorDrawables.

This is assumed to be the premise of wrap_content height.

This does not resize the picture, but centers it vertically. If I set the value of gravity to fill_vertical , it changes only on this axis and the aspect ratio is violated.

Is there a way to achieve this in XML without using ImageViews or other layouts? Can this be done programmatically? Or do I need a different layout?

+6
source share

Source: https://habr.com/ru/post/1013836/


All Articles