【问题标题】:Flutter Custom Splash ViewFlutter 自定义启动画面
【发布时间】:2024-04-29 02:25:01
【问题描述】:

尝试在 Flutter android 中实现自定义闪屏视图。 Launchbackground.xml 不符合我的要求。我有 2 张图片,一张是背景图片,另一张是顶部图片。

尝试这个 url 自定义闪屏会话 Creating a custom SplashScreen

分享示例代码

class SplashScreen : SplashScreen {
override fun createSplashView(context: Context, savedInstanceState: Bundle?): View? {
    TODO("Not yet implemented")
    //return SplashActivity();
    return LayoutInflater.from(context).inflate(R.layout.activity_splash, null, false);

}

override fun transitionToFlutter(onTransitionComplete: Runnable) {
    TODO("Not yet implemented")
    //mySplashView.animateAway(onTransitionComplete);
    onTransitionComplete.run();
}

}

<RelativeLayout 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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/spalshscreenbg"
android:fitsSystemWindows="false"
>

<ImageView
    android:id="@+id/logo_id"
    android:layout_marginTop="30dp"
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    android:src="@drawable/topimage"/>

【问题讨论】:

  • 黑屏先显示后只显示闪屏。这是因为 manifest.xml 文件中的主题设置 android:theme="@style/LaunchTheme"

标签: android flutter splash-screen


【解决方案1】:

你可以试试这个包https://pub.dev/packages/flutter_native_splash,因为它为你做了很多工作。这只是一个建议,绝对应该是一个评论,但我没有足够的代表。

【讨论】:

  • 在使用单一图像解决方案(如背景主题选项)时,图像会拉伸。将图像分成 3 部分,这就是插件可能无法正常工作的原因。