我打算在我的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