Matt
Matt

Reputation: 447

Android - How can I display my splash screen graphic larger?

I can't seem to figure out how to get my splash screen graphic to display larger, can anyone help? My image is a 288x69 pixel png file, but on the android device it renders tiny and I can't figure out how to change it. My splash screen works perfect, except for the image size. It's drawn with android:drawable in the xml, but no matter what I try it just won't render any larger. Any tips would be greatly appreciated!

The image is added to android studio under res/mipmap/.. and the xxxhdpi version is 192 x 192 pixels after the import into android studio.

To create the splash, in my AndroidManifest.xml I have the following:

        <activity
        android:name=".SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Under res/drawable I created background_splash.xml that contains this:

<?xml version="1.0" encoding="utf-8"?>

<item
    android:drawable="@color/white"
    android:id="@+id/splashDrawable"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>


<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/my_logo"
        android:id="@+id/splashLogo"/>

</item>

In my java folder I have SplashActivity.java with the following, which causes the splash to go away when the app is finished loading:

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();
}

}

In my styles.xml file I have this:

  <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

Upvotes: 2

Views: 4098

Answers (2)

Matt
Matt

Reputation: 447

For anyone else who is reading this with the same problem;

The final solution for me was to use the /res/drawable folder instead of /res/mipmap. On your hard disk, outside of android studio, browse to app/src/main/res and make sure you have folders named drawable-hdpi, drawable-mdpi, drawable-xhdpi and drawable-xxhdpi. Manually resize your images to whatever size you think is appropriate for each size and copy the images in. Now flip back to android studio and the images should show up in the /res/drawable area of android studio. Now I change my res/drawable/background_splash.xml file to reference the @drawable instead of @mipmap as shown below, and presto it works! I've only tested a couple of devices, but the image looked good. I'm not 100% sure it's choosing the proper resolution, but it looks appropriate.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:drawable="@color/white"
    android:id="@+id/splashDrawable"
    android:layout_width="10px"
    android:layout_height="10px"/>


<item>
    <bitmap
        android:gravity="center"
        android:width="10px"
        android:height="10px"
        android:src="@drawable/bodysite_logo"
        android:id="@+id/splashLogo"/>

</item>

Upvotes: 2

rupesh jain
rupesh jain

Reputation: 3430

You need an image with higher resolutions.These days the phone displays have around 300dpi which is much less than what you image resolution is. That is the reason you are seeing small image.

Upvotes: 1

Related Questions