上下文
这与闪屏图像的响应速度有关,根据我的研究,这只是因为Capacitor Docs - Splash Screen缺少文档。
问题
这个问题是在实现capacitor的闪屏插件时开始的。通常这个实现是在你创建整个项目时从头开始的。但是它在有拉伸宽高比的设备上不太好用(例如Google泛指el 2 XL)或具有胖宽高比的设备(例如iPad Pro)。甚至有一些场景中,闪屏图像会四处移动或收缩/扩展(在加载时)。
目视解释
换句话说,原生实现会导致启动画面像下面的图像一样。如果设备被拉伸或变胖,图像的纵横比就不会被保留。
4条答案
按热度按时间nwo49xxi1#
因此,我们的目标是不使这些图像被拉伸或变胖。要保持图像像在标准纵横比图像。要解决这个问题,并使启动图像成为响应天文数字的各种屏幕设备和纵横比,你将不得不操纵:
#1电容器配置JSON(离子项目)
#2应用组件TS(离子项目)
#3 Styles.xml(Android项目)
就是这样!所有的图像现在都保留了纵横比,并且它们将始终对所有设备做出响应。
参考
wn9m85ua2#
如果你得到闪屏两次( Flink )尝试在style.xml(android)
gcxthw6b3#
Solutions suggested in other posts may work for you if you use a plain color as the background of your splash screen, but if you use a complex image (like a gradient), here is what you need to know:
If you want a seamless transition between your splashscreen and your app, you need to install
@capacitor/splash-screen
as the Android<item name="android:background">@drawable/splash</item>
will not allow you to fade out the splash screen, furthermore when the Android splash screen is replaced by your Ionic App, you will experience a brief empty screen while the WebView is rendered.The
@capacitor/splash-screen
allows you to mitigate this by choosing yourself when the splash-screen should be hidden and how long the fade out should take.@capacitor/splash-screen
does NOT replace the native Android splash screen<item name="android:background">@drawable/splash</item>
, instead it create an AndroidImageView
as soon as the Ionic App is open (after the native Splash Screen) and then fades out to the WebView.You could hide the native Android splash screen to just use the
@capacitor/splash-screen
one by setting<item name="android:background">@null</item>
for the native splash screen, but this is considered as a bad practice as it will give the illusion of hanging out for a few moment each time you launch your app (the time required for the Ionic App to be created and displayed on screen).Finally, if you want the native Android splash screen to cover the entire screen and keep its aspect ratio, this is simply not possible (at least with Android 11 and earlier), you can only do this with an
ImageView
after the app as already booted.So... Here is what you can do to mitigate this :
First, make sure the config for the native Android splash screen and the splash screen created by
@capacitor/splash-screen
are the same, so you don't get a "resize" when it goes from the first one to the second one.Then, you'll have to split you splash screen in 2 layers, one for the background (that can be stretched to fill the viewport without keeping its aspect ratio), and one for your logo (or other element that sould be centered and keep its aspect ratio).
Then, create a custom drawable for your splash screen (i.e. drawable/launch_splash.xml), that will allow you to create a splash screen with as many layers as you want (in our case 2, one for the background, one for the logo).
And finally, use this custom drawable in place of the original splash screen.
Here is a full example of what I did:
capacitor.config.ts
(Make sure you rebuild your app after you make any changes to the
capacitor.config.ts
or report the changes yourself to thecapacitor.config.json
file).android/app/src/main/assets/capacitor.config.json
android/app/src/main/res/values/styles.xml
android/app/src/main/res/drawable/launch_splash.xml
src/app/tabs/tabs.page.ts
yvt65v4c4#
当我在Android设备上将我的应用程序从Capacitor v3升级到Capacitor v4时,闪屏再次扭曲。我必须做的是在drawable-folders(闪屏图像所在的位置)中创建9-patch-png文件,而不是常规的png文件。
我按照以下指南创建了这些文件:https://www.joshmorony.com/creating-a-dynamic-universal-splash-screen-for-capacitor-android/