Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating background drawable using layer-list, icon getting stretched

Hi I am trying to create a background drawable for my splash screen which I'll be setting in theme itself. But the bitmap drawable used to keep in the center is getting stretched and I am not able to figure how to keep it normal. Below is my drawable code: splash_screen_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
            android:angle="360"
            android:centerColor="@color/colorAccentXDark"
            android:endColor="@color/Black"
            android:gradientRadius="500dp"
            android:startColor="@color/colorAccentXDark"
            android:type="radial"
            android:useLevel="false" />
    </shape>
</item>
<item
    android:bottom="50dp"
    android:top="50dp">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:innerRadius="500dp"
        android:innerRadiusRatio="1"
        android:shape="oval">
        <gradient
            android:angle="360"
            android:centerColor="@color/colorAccentXDark"
            android:endColor="@color/colorAccentXDark"
            android:gradientRadius="400dp"
            android:startColor="@color/colorAccent"
            android:type="radial"
            android:useLevel="false" />
    </shape>
</item>
<item android:gravity="center">
    <bitmap android:src="@drawable/ty_logo" />
</item>
</layer-list>

Here is code where I am setting this drawable as background of an activity:

 <style name="TYTheme" parent="SearchActivityTheme.NoActionBar">
    <item name="colorPrimaryDark">@color/colorAccentXDark</item>
    <item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
    <item name="android:windowBackground">@drawable/splash_screen_bg</item>
</style>

So here the bitmap drawable ty_logo is an png is getting stretched in my phone. Since there is no scaleType option with bitmapDrawable I don't know how to handle it.

like image 343
himanshu1496 Avatar asked Mar 21 '16 06:03

himanshu1496


Video Answer


1 Answers

Add gravity to your bitmap set to center.

<item android:gravity="center">
    <bitmap android:src="@drawable/ty_logo" 
            android:gravity="center" />
</item>
like image 126
nt-complete Avatar answered Nov 03 '22 00:11

nt-complete