我打算在我的Xamarin Android项目中创建一个闪屏。布局在全屏幕中不可见Xamarin Android中的活动
我有以下布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center" android:background="#11aaff">
<ImageView
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/splash" />
</LinearLayout>
下面的代码:
[Activity(Label = "My Xamarin App", MainLauncher = true, NoHistory = true, Theme = "@android:style/Theme.Light.NoTitleBar.Fullscreen",
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class SplashScreenActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.SplashScreen);
// Create your application here
//var intent = new Intent(this, typeof(MainActivity));
//StartActivity(intent);
//Finish();
}
protected override void OnStart()
{
base.OnStart();
// Create your application here
var intent = new Intent(this, typeof(MainActivity));
StartActivity(intent);
}
}
启动应用程序后,我得到一个白屏(注意主题)和我的第二个活动( MainActivity
)几秒钟后显示。
如果我删除StartActivity
并仅显示启动画面,它将显示白色屏幕约1-2秒,然后显示图像和蓝色空白(如预期) - 显然第二个活动未启动。
我应该怎么做才能让布局立即出现?
谢谢,我真的应该使用官方的Xamarin方法在第一位:) – Nestor