2016-09-20 21 views
0

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秒間白い画面が表示され、画像と青色の背景が表示されます(2番目のアクティビティは開始されていません)。

レイアウトをすぐに表示するにはどうすればよいですか?

答えて

1

カスタムレイアウトの代わりにカスタムテーマを使用できます。

ただ、ノート、このソリューションでは、プロジェクトに次のナゲットパッケージを追加する必要があります動作するために: Xamarin.Android.Support.v4とXamarin.Android.Support.v7.AppCompatで述べたように 基準リンクが蛇行する。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
    <color android:color="@color/splash_background"/><!-- Your BG color here --> 
    </item> 
    <item> 
    <bitmap 
     android:src="@drawable/splash"<!-- your splash screen image here --> 
     android:tileMode="disabled" 
     android:gravity="center"/> 
    </item> 
</layer-list> 

:基本的には、次のようなものを使用して描画可能なフォルダ内の.xmlファイルを作成 Creating a Splash Screen

私はしばらくの間は、背中や参照など、このリンクを使用したことをしなければなりませんでしたそして、あなたは(リソース/値のデフォルトでは)のstyles.xmlファイルを編集し、追加します。

<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light"> 
    <item name="android:windowBackground">@drawable/splash_screen</item><!-- here you should put the name of the file you just created in the drawable folder --> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
</style> 

最後に、あなたのスプラッシュ画面代わりに活動AppCompatActivityを拡張する必要がありますし、テーマは次のように、カスタムする必要があります:

[Activity(Label = "My Xamarin App", MainLauncher = true, NoHistory = true, Theme = "@style/MyTheme.Splash", 
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 
    public class SplashScreenActivity : AppCompatActivity 

私はこの情報がお役に立てば幸いです。

+0

ありがとう、私は本当に最初の場所で、公式のXamarinのアプローチを使用している必要があります:) – Nestor

関連する問題