2017-04-16 172 views
0

我想知道,如果我可以顯示某種動畫,直到我的活動加載。因爲當我啓動我的應用程序時,大約需要5秒鐘才能看到活動。在加載之前,會顯示一個白色屏幕(請參閱以下的圖片)。我的活動加載之前是否可以顯示動畫?

enter image description here

我可以那樣做嗎?

如果可以,應該怎麼做?

非常感謝您。 祝您有美好的一天。

+0

你可以顯示進度對話框 - 加載動畫5秒 – rafsanahmad007

+0

但我不知道它是否持續5秒在所有設備上,或者只是我的 – Freddie

回答

0

如果您下載一些數據,或者你長了ridiculusly大列表視圖 - 你還有其他問題....

下載數據:減少所需要的應用程序工作

列表視圖數據的大寫金額 - 用戶如果這是一個合法的問題 - 那麼你需要某種類型的監聽程序(表示任務完成時),比如Thread.join(),並且每當該監聽程序激活時 - 它應該轉到另一個意圖並且最後一次殺死一個(殺死你需要使用finish();)

+0

我初始化6個按鈕並請求運行時權限。我認爲請求權限可能會導致此問題。 – Freddie

+0

如果權限正確實施 - 它不應該導致任何問題。 –

+0

https://github.com/WithoutCaps/FileEditor/blob/master/app/src/main/java/site/withoutcaps/fileeditor/FileEditor.java其實有一些基本的(有點兒糟糕的)實現。時間你的一些方法,並試圖找出它因爲錯誤 –

0

我不知道你是否可以在那裏放置一個動畫,但是你可以使用帶有你的應用徽標的閃屏或任何其他的背景。您花費在查看此初始屏幕上的時間恰好是應用程序自行配置所花費的時間。所以在任何設備上都沒有區別。

  1. 在RES創建XML可繪製/可繪:

    <item 
        android:drawable="@color/gray"/> 
    
    <item> 
        <bitmap 
         android:gravity="center" 
         android:src="@mipmap/ic_launcher"/> 
    </item> 
    

  • 導航到您的樣式。 xml文件併爲您的splash活動添加新主題。

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
        <!-- Customize your theme here. --> 
    </style> 
    
    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> 
        <item name="android:windowBackground">@drawable/background_splash</item> 
    </style> 
    

  • 創建閃屏的活動。無需爲此活動設置視圖。觀點來自主題。當您在主題中爲您的飛濺活動設置UI時,它立即可用。

  • public class SplashActivity extends AppCompatActivity { 
    @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Intent intent = new Intent(this, MainActivity.class); 
    startActivity(intent); 
    finish(); 
    } 
    } 
    
  • 在新的SplashTheme,設置窗口的背景屬性對XML繪製。在您的AndroidManifest中將其配置爲您的飛濺活動的主題。XML:
  • enter image description here

    +0

    這個網站代碼格式化有問題!有人請糾正。 –

    0

    嘗試使用ProgressDialogAsyncTask

    new YourFragment.YourAsyncTask().execute(); 
    

    使用這個庫sweet-alert-dialog更多的動畫加載

    class YourAsyncTask extends AsyncTask<Void, Void, Void> { 
        SweetAlertDialog pDialog; 
        @Override 
        protected void onPreExecute() { 
         //show your dialog here 
         super.onPreExecute(); 
         pDialog = new SweetAlertDialog(getContext(), SweetAlertDialog.PROGRESS_TYPE); 
         pDialog.getProgressHelper().setBarColor(Color.parseColor("#fdc80b")); 
         pDialog.setTitleText("Loading..."); 
         pDialog.setCancelable(false); 
         pDialog.show(); 
        } 
        @Override 
        protected Void doInBackground(Void... params) { 
         return null; 
        } 
        @Override 
        protected void onPostExecute(Void result) { 
         //hide your dialog here 
         super.onPostExecute(result); 
         pDialog.dismissWithAnimation(); 
         } 
        } 
    } 
    

    }