Maxqueue
Maxqueue

Reputation: 2454

Xamarin splash screen only supports a single image

Is it really not possible to have rotating splash screen for Android and Ios?

For Ios i have a document of type

type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB"

which works fine but there doesn't appear to be a way to rotate this with random images.

For Android i have the following at the top of the SplashActivity class

[Activity(MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash",
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation=ScreenOrientation.Portrait)]

What i am really trying to accomplish is to have a splash screen that is a rotation of about 6 images. So first time user opens app they would see first image and so on.

I can't imagine that people have not wanted splash screen to be dynamic. For example maybe on Halloween app would display pumpkin on splash etc.

Am i just missing something here?

Upvotes: 1

Views: 284

Answers (1)

Wendy Zang - MSFT
Wendy Zang - MSFT

Reputation: 10978

In Android, you could create a animations for Splash screen. I use the jump for reference. You could create the .xml file according to what you want.

Create a Anim folder and put the hyperspace_jump.xml file in it.

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXScale="1.0"
    android:toXScale="1.4"
    android:fromYScale="1.0"
    android:toYScale="0.6"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fillAfter="false"
    android:duration="700" />
<set
    android:interpolator="@android:anim/accelerate_interpolator"
    android:startOffset="700">
    <scale
        android:fromXScale="1.4"
        android:toXScale="0.0"
        android:fromYScale="0.6"
        android:toYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="400" />
    <rotate
        android:fromDegrees="0"
        android:toDegrees="-45"
        android:toYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="400" />
</set>

Create the layouts:

SplashScreen Layout:

 <RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
   p1:minWidth="25px"
   p1:minHeight="25px"
   p1:layout_width="match_parent"
   p1:layout_height="match_parent"
   p1:background="@android:color/white"
   p1:id="@+id/relativeLayout1">

   <ImageView
       p1:layout_width="wrap_content"
       p1:layout_height="wrap_content"
       p1:id="@+id/imageView"
       p1:layout_centerVertical="true"
       p1:layout_centerHorizontal="true"
       p1:src="@drawable/a01" />
   </RelativeLayout> 

MainLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Main Activity Started"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"/>
</LinearLayout>

Code Behind:

SplashScreenActivity:

public class SplashScreenActivity : Activity
{
ImageView imageView;
Animation view_animation;
TextView textview;
protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    RequestWindowFeature(Android.Views.WindowFeatures.NoTitle);
    SetContentView (Resource.Layout.SplashScreen);
    imageView = (ImageView)FindViewById(Resource.Id.imageView);
    
    view_animation = AnimationUtils.LoadAnimation(this,Resource.Animation.hyperspace_jump);
     
    imageView.StartAnimation(view_animation);
    view_animation.AnimationEnd += Rotate_AnimationEnd;
    
}

private void Rotate_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
{
    Finish();
    StartActivity(typeof(MainActivity));
}
}

MainActivity:

 protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    SetContentView(Resource.Layout.Main);
    Toast.MakeText(this, "Welcome to MainActivity", ToastLength.Long).Show();
}

Screenshot:

enter image description here

You could download from the GitHub for reference. https://github.com/WendyZang/Test/tree/master/SplashScreenDemo

Updated:

Create a new activity to judge the day of week.

Activity1.cs: Remove the MainLauncher = true from the SplashScreenActivity.

 [Activity(Label = "SplashScreenDemo", MainLauncher = true)]
public class Activity1 : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here
        var dateTime = DateTime.Today;
        if (dateTime.DayOfWeek== DayOfWeek.Thursday)
        {
            StartActivity(typeof(ThursdayActivity));
        }
        else if (dateTime.DayOfWeek == DayOfWeek.Monday)
        {
            StartActivity(typeof(SplashScreenActivity));
        }
    }
}

Create a new splash screen layout ThursdayLayout with different image in ImageView and create a new activity for this named ThursdayActivity.

After that you could run the ThursdayActivity with Thursday splash screen when it is Thursday.

Upvotes: 2

Related Questions