creating background drawable using layer-list, icon getting stretched creating background drawable using layer-list, icon getting stretched android android

creating background drawable using layer-list, icon getting stretched


Add gravity to your bitmap set to center.

<item android:gravity="center">    <bitmap android:src="@drawable/ty_logo"             android:gravity="center" /></item>


I hope that ty_logo is of suitable pixels and you have provided different pixels image for various device screens (ldpi, mdpi, hdpi, xhdpi, etc).If not, do go through this answer to a similar problem you find yourself in : Resize images in bitmap in xml

Otherwise, this can be easily solved if your target version is for API 23 as <item> has width,height,gravity attributes provided for them.

And if not, the following code should work, using gravity attribute for bitmap. Again, this is going by the assumption that your logo is not having more pixels than resolution of the devices.

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


You can wrap bitmap inside ScaleDrawable <scale> and use ScaleDrawable inside LayerListDrawable.

<item android:gravity="center">    <scale android:drawable="@drawable/ty_logo"         android:scaleHeight="80%"         android:scaleWidth="80%" >    </scale> </item>