简体   繁体   English

Cordova android 闪屏失真

[英]Cordova android splashscreen are distorted

I have a Cordova app with a splashscreen at start.我有一个 Cordova 应用程序,启动时有启动画面。 The splashscreen is shown but it's distorted.启动画面已显示,但已失真。 It seems to don't take the good resolution.它似乎没有采取好的分辨率。

My splash is a Bitmap image, I don't care if its cropped but I don't want it to be distorted.我的启动画面是 Bitmap 图像,我不在乎它是否被裁剪,但我不希望它被扭曲。

I have the following structure with splashscreen at differents size according to the doc :根据文档,我有以下不同大小的闪屏结构:

drawable-xhdpi/
  splash.png   // 960 x 720px
drawable-hdpi/
  splash.png   // 640 x 480px
drawable-mdpi/
  splash.png   // 470 x 320px
drawable-ldpi/
  splash.png   // 426 x 320px

Is it a Cordova bug?它是 Cordova 错误吗? Did I miss something?我错过了什么?

I tested with few devices like Galaxy s3 mini, HTC but I got the samed problem on each device.我用 Galaxy s3 mini、HTC 等少数设备进行了测试,但我在每台设备上都遇到了同样的问题。

It works well in iOs.它在 iOs 中运行良好。

I used cordova 3.3 and upgraded it recently to 3.4 but got the problem still persist.我使用 cordova 3.3 并最近将其升级到 3.4 但问题仍然存在。

In my case, adding 在我的情况下,添加

<preference name="SplashMaintainAspectRatio" value="true" />

to config.xml solved the distortion problem for me. to config.xml解决了我的失真问题。

I've just changed the sizes to: 我刚刚将尺寸改为:

xlarge (xhdpi): 720 x 1280
large (hdpi): 480 x 800
medium (mdpi): 320 x 480
small (ldpi): 200 x 320

And it works perfectly 而且效果很好

To anyone who came across this question and is using capacitor :对于遇到此问题并使用电容器的任何人:

Capacitor < 4电容 < 4

There is a similar setting like the one suggested for Cordova that can be added to capacitor.config.json有一个与Cordova建议的设置类似的设置,可以添加到capacitor.config.json .config.json

"SplashScreen": {
    "androidScaleType": "CENTER_CROP"
}

There's an open issue on Github with more configuration examples here Github 上有一个未解决的问题,这里有更多配置示例

Capacitor >= 4电容 >= 4

Unfortunately, starting from capacitor 4 splash screens are being squashed despite the settings, so the only way to make it work seems to be 9 patch images (can be managed in Android Studio directly).不幸的是,尽管进行了设置,但从电容器 4 开始,闪屏被压扁,因此使其工作的唯一方法似乎是9 个补丁图像(可以直接在 Android Studio 中管理)。

Following this tutorial solved the issue for me, and this seems the best way to deal with future capacitor changes.遵循本教程为我解决了这个问题,这似乎是处理未来电容器变化的最佳方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM