【发布时间】:2019-06-26 14:08:13
【问题描述】:
我正在使用 Flutter 创建一个新应用,并希望在初始启动屏幕上添加自定义图像。
图像出现在初始屏幕上,但是大约有半秒钟的时间,它看起来被拉伸了,看起来不太好。
我一直在寻找,但很难找到有同样问题的人。
有什么想法吗?
我尝试使用 mipmap 提供可变大小的图像,但产生了相同的结果。
launch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/green" />
<item>
<bitmap
android:gravity="center_horizontal"
android:src="@drawable/ic_logo"
android:tileMode="disabled"/>
</item>
</layer-list>
style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<color name="green">#b7dd05</color>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutter_app">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_app"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
我不介意图像在渲染中需要一秒钟,但首先拉伸它并不理想。
【问题讨论】:
-
我遇到了完全相同的问题。如果我在普通的 Android 应用程序中使用 xml,则启动画面看起来不错,符合预期。我不知道 Flutter 是如何破坏这种行为的。如果您找到解决方案,请在 stackoverflow 上回答您的问题。
标签: android xml flutter bitmap splash-screen