Xamarin:使用布局的启动画面

Xamarin : Splash screen using a Layout

我正在尝试为我的 android 应用程序创建初始屏幕,如此 link http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

中所示

不幸的是,这个 link 只是展示了如何使用可绘制对象制作启动画面。但我需要做的是使用 Layout 创建启动画面,以便我可以轻松自定义它的外观并使其与不同的屏幕尺寸兼容。

谢谢

您可以做的是创建一个 Activity 来代表您的闪屏。例如:SplashActivity。然后,当您的 SplashActivity 创建时,您将启动一个持续时间为 3 秒的计时器(例如:System.Timers.Timer)。当这 3 秒过去后,您只需为您的应用程序启动主程序 activity。

要防止用户导航回启动画面 activity,您只需将 NoHistory = true 属性 添加到 Activity 属性(就在 activity class减速)。

参见示例:

    [Activity(MainLauncher = true, NoHistory = true, Label = "My splash app", Icon = "@drawable/icon")]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Splash);

            Timer timer = new Timer();
            timer.Interval = 3000; // 3 sec.
            timer.AutoReset = false; // Do not reset the timer after it's elapsed
            timer.Elapsed += (object sender, ElapsedEventArgs e) =>
            {
                StartActivity(typeof(MainActivity));
            };
            timer.Start();
        }
    };

    [Activity (Label = "Main activity")]
    public class MainActivity : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);
        }
    }