歡迎您光臨深圳塔燈網(wǎng)絡(luò)科技有限公司!
          電話圖標(biāo) 余先生:13699882642

          網(wǎng)站百科

          為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴

          Flutter 首屏優(yōu)化

          發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):3319

          Android App 一般在啟動的時(shí)候會出現(xiàn)白屏、黑屏,持續(xù) 0.5s - 3s (看 App 啟動加載復(fù)雜度 與 手機(jī)性能)。

          其主要的原因是默認(rèn)的 Andraid App 是沒有設(shè)置啟動圖的。在啟動的時(shí)候,Andraid App 需要加載各種資源,包括創(chuàng)建 Activity 等。

          如果第一個(gè)Activity,還沒創(chuàng)建完成,就會看到白屏、黑屏,一般解決這個(gè)問題就是為 Andraid App 設(shè)置一個(gè)啟動圖。就像淘寶 App 那樣,啟動的時(shí)候會看到一張關(guān)于淘寶的圖片。

          而 iOS App 默認(rèn)設(shè)置了啟動圖,就不會像 Android App 那樣出現(xiàn)白屏、黑屏。

          在打開 Flutter App 時(shí)會出現(xiàn)短暫的白屏現(xiàn)象(Android),這并不是 Flutter 的特例,在 React Native 上同樣如此。因此在 React Native 上解決白屏的處理方式與 Flutter 類似。

          添加啟動圖

          在 xml 里,添加啟動圖。當(dāng) App 打開時(shí)會先看到啟動圖,接著渲染 Flutter 所管理的 Activity。

          首先在 android/app/src/main/res/drawable-hdpi 里加上一個(gè)圖片作為程序啟動圖(名稱隨意,例如:bg.png),然后修改 android/app/src/main/res/values/styles.xml

          <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- 這里將剛剛那張圖片設(shè)置為背景圖片, bg對應(yīng)圖片名稱 --> <item name="android:windowBackground">@drawable/bg</item> </style> 

          或者,在 android\app\src\main\res\drawable\launch_background.xml 里添加,也行。

          <?xml version="1.0" encoding="utf-8"?> <!-- Modify this file to customize your launch splash screen --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/white" /><!-- You can insert your own image assets here --> <item> <bitmap android:gravity="center" android:src="@mipmap/bg" /> </item> </layer-list> 

          最后,記得在 Flutter 底端頁面上設(shè)置背景為非透明。

          @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('應(yīng)用'), ), body: new Container( color: Colors.white, ), ); } 

          本頁內(nèi)容由塔燈網(wǎng)絡(luò)科技有限公司通過網(wǎng)絡(luò)收集編輯所得,所有資料僅供用戶學(xué)習(xí)參考,本站不擁有所有權(quán),如您認(rèn)為本網(wǎng)頁中由涉嫌抄襲的內(nèi)容,請及時(shí)與我們聯(lián)系,并提供相關(guān)證據(jù),工作人員會在5工作日內(nèi)聯(lián)系您,一經(jīng)查實(shí),本站立刻刪除侵權(quán)內(nèi)容。本文鏈接:http://m.cjxv.cn/17593.html
          相關(guān)APP開發(fā)