Telavian
Telavian

Reputation: 3832

Splash screen is resizing incorrectly

I am using the style below to show a splash screen in my Xamarin Android application however the image always shows with incorrect sizing. I would like it to resize with the correct dimensions however it always expands to fit the screen.

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splashscreenimage</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:adjustViewBounds">true</item>
    <item name="android:scaleType">centerCrop</item>
  </style>
</resources>

The splash screen activity

  [Activity(MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true)]
  public class SplashScreenActivity : Activity
  {
    protected override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);

      // Start our real activity
      StartActivity(typeof(LoginActivity));
    }
  }

Upvotes: 12

Views: 27538

Answers (4)

ivan.panasiuk
ivan.panasiuk

Reputation: 1259

For background drawable you should use layer-list. For example make bitmap_splash.xml:

<item android:drawable="@color/background"/>

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

and then use it in your style:

...
<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/bitmap_splash</item>
...

Upvotes: 9

jwir3
jwir3

Reputation: 6209

Take a look at:

Android: Scale a Drawable or background image?

Basically, this allows you to specify how to clip or stretch an image when the image is smaller than the view bounds of the screen. I think the author of this answer gives a good explanation, and it might be what you're looking for.

Upvotes: -3

t9mike
t9mike

Reputation: 1626

One issue is that windowBackground is sized to full screen size, inclding status bar at top or bottom of device. But the status bar is still shown. My response to Android Activity Background Image uses windowContentOverlay, which excludes the status bar.

Upvotes: 4

jHogen
jHogen

Reputation: 123

When I had trouble displaying images correctly in my app I found this helpfull site: Android scale types

It shows the outcome of the different types of scale that you can use. Hope this helps!

Upvotes: -3

Related Questions