1

I've followed the instructions from Xamarin here: http://docs.xamarin.com/android/tutorials/Creating_a_Splash_Screen

This works very well, but does not mention landscape mode at all. I can rotate my splash image to be portrait size which gets the best results but it's still not ideal: the splash image rotates away as it disappears and the main activity is launched. This is because the splash activity is in portrait mode and the main activity is in landscape.

I've tried adding 'screenOrientation = ScreenOrientation.Landscape` to the splash activity's Activity attribute, but this results in the splash screen not being displayed.

According to this question, it is not possible to disable the rotation animation, so I'd really like to find out how to make this initial splash activity display in landscape mode, or some other approach that achieves the same result. Below is the code for the splash activity, with the offending ScreenOrientation parameter.

[Activity(
    Label = "The App Name",
    Icon = "@drawable/icon", 
    MainLauncher = true, 
    Theme = "@style/Theme.Splash", 
    //ScreenOrientation = ScreenOrientation.Landscape,
    NoHistory = true)]
public class ActivitySplash : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Start our real activity
        StartActivity(typeof(ActivityMain));
    }
}
Community
  • 1
  • 1
Aranda
  • 855
  • 8
  • 17

4 Answers4

1

All you have to do is create a folder in Resources called drawable-land. Then, place your Splash.png in there. No extra c# is required.

Guy

Guy Micciche
  • 378
  • 1
  • 4
  • 11
  • And what if this doesn't work? I tried this, but the app simply always seems to use the portrait versions of the splashscreen, even when a landscape mode in the "-land" folder exists – PaulVrugt Jan 16 '18 at 13:59
0

Try adding the following line to your splash screen activity.

RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;

Like this:

[Activity(
    Label = "The App Name",
    Icon = "@drawable/icon", 
    MainLauncher = true, 
    Theme = "@style/Theme.Splash", 
    //ScreenOrientation = ScreenOrientation.Landscape,
    NoHistory = true)]
public class ActivitySplash : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);


        RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;


        // Start our real activity
        StartActivity(typeof(ActivityMain));
    }
}
Ivozor
  • 976
  • 8
  • 23
  • Thanks for posting, but unfortunately it doesn't help. It makes it worse as now the splash image starts squashed in portrait then rotates to landscape. – Aranda Jan 11 '13 at 14:16
  • I've decided to just live with the small rotation animation when it switches between the two activities. If you display a different image it isn't so bad. – Aranda Jan 11 '13 at 14:17
0

I also had the a similar problem on the Nexus 7, if you use RequestedOrientation = ScreenOrientation.Landscape; inside the OnCreate method as it was mentionned, there will be a few sec where the screen will be displayed in portrait.

I also tried to put every settings in the .axml of my splash screen and inside its style but no effects.

The Only way I was able to make it work is by setting the property ScreenOrientation = ScreenOrientation.Landscape in the Activity annotation

[Activity(Label = "MySplashScreen", Theme = "@style/SplashTheme", NoHistory = true, MainLauncher = true, ScreenOrientation = ScreenOrientation.Landscape)]
    public class SplashScreenActivity : Activity
{
// your code goes here ...
}

That's the only way I got it worked right. I think you should use that and investigate why the image is not displayed when you set this property.

ForceMagic
  • 6,230
  • 12
  • 66
  • 88
  • You say "The Only way I was able to make it work is by setting the property in the Activity annotation", but which property do you mean? Presumably it's `ScreenOrientation = ScreenOrientation.Landscape`, but I have tried this and on my Galaxy SII and HTC Descire I got a black screen instead of the splash image. – Aranda Aug 05 '13 at 07:13
  • @Aranda Good point, I edited my post. It is really the ScreenOrientation property. If you get a Black screen, is it possible that your SplashScreen activity is not showing long enough for you to see it? I use a timer to ensure the splash screen will stay at least 2-3 secondes before it loads the next activity. – ForceMagic Aug 05 '13 at 14:08
  • Yeah, I suppose it's possible it's disappearing too quickly - I don't force it to stay for any period of time. It just seems unlikely as when it's set to portrait (or the property is removed), it shows almost instantly. – Aranda Aug 05 '13 at 14:55
  • @Aranda Hmm, I did noticed a difference though, when set to landscape there is a small animation on application start where you see the device switching to landscape. But at least the image is never squished during that animation (in my case). Try with a 1-2 sec timer just to see if it's not because of this behavior or maybe try starting the app while the device is already on landscape mode. – ForceMagic Aug 05 '13 at 15:19
  • As far as I can tell, Android is (almost) always in portrait mode until an app runs and switches it to landscape. (EDIT: Holding the device sideways makes no difference). Perhaps an app that starts in Landscape is delayed a little, just enough that my fast splash is not displayed at all. Have to give it a try when I get a chance. I didn't really want the timer as I want the app to load as quickly as possible but also to display a splash with no delay. The rotation animation isn't a huge deal - it just looks a little unprofessional. – Aranda Aug 05 '13 at 16:07
  • @Aranda Well, I actually use the timer just to ensure the splash screen will be displayed while loading other things. I used a wait time of 1 sec, but you can probably set it to 500ms or a bit lower and your splash will show up while not slowing the app loading time. – ForceMagic Aug 05 '13 at 16:25
0

I know this post is old but for those that land here: Use an xml layout with an image in the center. This is how they do it in the Xamarin Splash Screen demo shown here: Splash Screen Demo

Post Impatica
  • 14,999
  • 9
  • 67
  • 78