2017-02-03 25 views
3

アプリの読み込み中にスプラッシュ画面が表示されます。私は、スプラッシュ画面のアイコンの下にアニメーションの進行状況バーを配置したいと思います。 XMLを使ってみましたが、クラッシュしています!無効なタグのプログレスバーが表示されます。アンドロイド - スプラッシュ画面のプログレスバー

ここで私は本当に使用してスプラッシュ画面を作りたくないのstyles.xml

<style name="AppTheme.BrandedLaunch" parent="AppThemeDark"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:windowBackground">@drawable/background_splash</item> 
</style> 

にここに私のbackground_splash.xmlファイルが

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item 
    android:drawable="@color/splash_screen_bg"/> 

<item> 
    <bitmap 
     android:gravity="center" 
     android:tileMode="disabled" 
     android:src="@drawable/ic_launcher"/> 
</item> 

<item> 
<ProgressBar 
    android:id="@+id/progressBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
/> 
</item> 
</layer-list> 

だ、スプラッシュ画面を呼び出すための私のコードですこのメソッドは本当に簡単だったので、別のメソッド。何か案は?

+0

splash.xmlファイルに直接アイコンと進行状況バーを入れないでください –

答えて

0

drawbarファイル内にprogressbarやimageview(ビットマップ)などのウィジェットを配置しないでください。レイアウトファイルに親のレイアウトを相対レイアウトにしてからrelativelayoutの背景色をsplash_screen_bgに設定し、imageviewとprogressbarを追加します相対レイアウト内。

0

ここに1つのハックがあります。

SplashActivity.java

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     final View rootView = getWindow().getDecorView().getRootView(); 
     rootView.setBackgroundDrawable(getResources().getDrawable(R.drawable.test)); 
     rootView.post(new Runnable() { 
      @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 
      @Override 
      public void run() { 
       ((AnimationDrawable) rootView.getBackground()).start(); 
      } 
     }); 
    } 

のtest.xml

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/list" 
     android:oneshot="false"> 
     <item 
      android:drawable="@drawable/frame_1" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_2" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_3" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_4" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_5" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_6" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_7" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_8" 
      android:duration="20" /> 
     <item 
      android:drawable="@drawable/frame_9" 
      android:duration="20" /> 

    </animation-list> 
1

キーは、このチュートリアルでは次のとおりです。 http://www.logicchip.com/android-splash-screen-progress-bar/ あなたが描画可能なフォルダに国連ファイルを作成する必要があります。たとえばsplas_screen.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="100dp" 
    android:layout_height="100dp"> 
    <item> 
     <color android:color="@color/main_color_grey_50"/> 
    </item> 
    <item> 
     <bitmap 
      android:gravity="center" 
      android:filter="true" 
      android:src="@drawable/logomies" 
      /> 
    </item> 
</layer-list> 

はあなたLAUNCHER活動などのSplashActivityを設定しなければならないのstyles.xml

<style name="SplashTheme" parent ="Theme.AppCompat.NoActionBar"> 
     <item name="android:windowBackground">@drawable/splash_screen</item> 
    </style> 

AndroidManifestファイルをファイルに新しいスタイルを追加します。

<application 
     android:name=".ActBenApplication" 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/ActivityTheme"> 

     <activity android:name=".main.ui.SplashActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" 
      android:theme="@style/SplashTheme"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".main.MainActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait"> 
     </activity> 
    </application> 

重要な部分はここに来て:あなたは、プログレスバーがなるレイアウトを作成しなければなりませんプログレスバーがスラッシュの表示されるように、このレイアウトには、バックグラウンドを持っていません。最後に、あなたのActivity.javaファイル内

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/splash_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".main.ui.SplashActivity"> 


    <ProgressBar 
     android:id="@+id/progressBar2" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:visibility="visible" 
     android:indeterminateOnly="true"/> 
</android.support.constraint.ConstraintLayout> 

:作成したレイアウトにsetContentViewとして

public class SplashActivity extends AppCompatActivity{ 

    @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 


     new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 
       // This method will be executed once the timer is over 
       // Start your app main activity 
       Intent i = new Intent(SplashActivity.this, MainActivity.class); 
       startActivity(i); 

       // close this activity 
       finish(); 
      } 
     }, 3000); 
    } 
} 

セット。それはすべて..!

関連する問題