简体   繁体   English

某些设备中的启动画面失真

[英]Distorted splash screen in some devices

I'm having trouble fixing the distorted splash screen issue on android.我在修复 android 上扭曲的闪屏问题时遇到了麻烦。 I'm using React native.我正在使用 React Native。 Note that this only happens to some devices, for example, I have a samsung with android version 4.2.2 (splash screen NOT distorted), while the samsung which has an android version of 8+ is having a distorted splash screen.请注意,这仅发生在某些设备上,例如,我有一个 android 版本为 4.2.2 的三星(启动画面未失真),而具有 8+ android 版本的三星的启动画面失真。

Below is the attached distorted and not distorted splash screens:以下是附加的扭曲和未扭曲的启动画面:

First image is the "NOT DISTORTED" display第一张图片是“NOT DISTORTED”显示

Second image is the "DISTORTED" display第二张图片是“DISTORTED”显示

This is the link for the guideline Splash Screen Guide这是指南 启动画面指南的链接

在此处输入图片说明 在此处输入图片说明

使您的图像视图的高度和宽度相等意味着两者都需要具有相同的大小

make resources available for all screen size and also what design you are using?为所有屏幕尺寸以及您使用的设计提供资源? can you post your xml?你可以发布你的xml吗?

Edited solution that will make your SplashScreen look great on all APIs including API21 to API23经过编辑的解决方案将使您的 SplashScreen 在包括 API21 到 API23 在内的所有 API 上看起来都很棒

First of all read this article and follow the GOOD way of making a splash screen.首先阅读这篇文章并遵循制作启动画面的好方法。

If your logo is distorted or wont fit and you are only targeting APIs24+ you can simply scale down your vector drawable directly in its xml file like so:如果您的徽标扭曲或不适合并且您只针对 APIs24+,您可以直接在其 xml 文件中缩小您的矢量可绘制对象,如下所示:

<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="640"
android:viewportHeight="640"
android:width="240dp"
android:height="240dp">
<path
    android:pathData="M320.96 55.9L477.14 345L161.67 345L320.96 55.9Z"
    android:strokeColor="#292929"
    android:strokeWidth="24" />
</vector>

in the code above I am rescaling a drawable I drew on a 640x640 canvas to be 240x240.在上面的代码中,我将在 640x640 画布上绘制的可绘制对象重新缩放为 240x240。 then i just put it in my splash screen drawable like so and it works great:然后我把它放在我的启动画面中,就像这样,它工作得很好:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque"
android:paddingBottom="20dp" android:paddingRight="20dp" android:paddingLeft="20dp" android:paddingTop="20dp">

<!-- The background color, preferably the same as your normal theme -->
<item>
    <shape>
        <size android:height="120dp" android:width="120dp"/>
        <solid android:color="@android:color/white"/>
    </shape>
</item>

<!-- Your product logo - 144dp color version of your app icon -->
<item
    android:drawable="@drawable/logo_vect"
    android:gravity="center">

</item>
</layer-list>

my code is actually only drawing the triangle in the picture at the bottom but here you see what you can achieve with this.我的代码实际上只是在底部的图片中绘制三角形,但在这里您可以看到使用它可以实现的目标。 Resolution is finally great as opposed to the pixelated edges I was getting when using bitmap.与使用位图时得到的像素化边缘相比,分辨率终于很棒了。 so use a vector drawable by all means (there is a site called vectr that I used to create mine without the hasle of downloading specialized software).所以一定要使用可绘制的矢量(有一个名为 vectr 的站点,我曾经创建我的站点,而无需下载专门的软件)。

EDIT in order to make it work also on API21-22-23编辑以使其也适用于 API21-22-23

While the solution above works for devices runing API24+ I got really disappointed after installing my app a device running API22.虽然上述解决方案适用于运行 API24+ 的设备,但在将我的应用安装到运行 API22 的设备后,我感到非常失望。 I noticed that the splashscreen was again trying to fill the entire view and looking like shit.我注意到闪屏再次试图填满整个视图并且看起来像狗屎。 After tearing my eyebrows out for half a day I finally brute-forced a solution by sheer willpower.撕了半天的眉毛,我终于凭着意志力强行解决了。

you need to create a second file named exactly like the splashscreen xml (lets say splash_screen.xml) and place it into 2 folders called drawable-v22 and drawable-v21 that you will create in the res/ folder (in order to see them you have to change your project view from Android to Project).您需要创建一个与启动画面 xml 完全相同的第二个文件(假设为 splash_screen.xml),并将其放入两个名为 drawable-v22 和 drawable-v21 的文件夹中,您将在 res/ 文件夹中创建该文件夹(以便您查看它们)必须将您的项目视图从 Android 更改为 Project)。 This serves to tell your phone to redirect to files placed in those folders whenever the relevant device runs an API corresponding to the -vXX suffix in the drawable folder, see this link .这用于告诉您的手机在相关设备运行与 drawable 文件夹中的 -vXX 后缀对应的 API 时重定向到放置在这些文件夹中的文件, 请参阅此链接 place the following code in the Layer-list of the splash_screen.xml file that you create in these folders:将以下代码放置在您在这些文件夹中创建的 splash_screen.xml 文件的图层列表中:

<item>
<shape>
    <size android:height="120dp" android:width="120dp"/>
    <solid android:color="@android:color/white"/>
</shape>
</item>

<!-- Your product logo - 144dp color version of your app icon -->
<item android:gravity="center">
    <bitmap android:gravity="center"
        android:src="logo_vect"/>

</item>

这些是文件夹的外观

For some reason for these APIs you have to wrap your drawable in a bitmap in order to make it work and jet the final result looks the same.出于某些原因,对于这些 API,您必须将 drawable 包装在位图中以使其工作并喷射最终结果看起来相同。 The issue is that you have to use the aproach with the aditional drawable folders as the second version of the splash_screen.xml file will lead to your splash screen not being shown at all on devices running APIs higher than 23. You might also have to place the first version of the splash_screen.xml into drawable-v24 as android defaults to the closest drawable-vXX folder it can find for resources.问题是您必须将这种方法与其他可绘制文件夹一起使用,因为 splash_screen.xml 文件的第二个版本将导致在运行 API 高于 23 的设备上根本不显示启动画面。您可能还必须放置将 splash_screen.xml 的第一个版本转换为 drawable-v24 作为 android 默认为它可以找到的最接近的 drawable-vXX 资源文件夹。 it finally worked for me它终于对我有用了

我的启动画面

Follow steps :请按照以下步骤操作:

1) Use only Icon and set Background as gradient drawable. 1) 仅使用 Icon 并将背景设置为渐变可绘制。

2) White Icon's width and height should be equal. 2)白色图标的宽度和高度应该相等。 Use Icon and place in XHDPI and XXHDPI drawable folder.使用 Icon 并放置在 XHDPI 和 XXHDPI 可绘制文件夹中。

Layout Dsign :布局设计:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sample">

  <ImageView
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:background="@android:color/white"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="90dp"/>
</RelativeLayout>

Drawable background sample.xml :可绘制背景 sample.xml :

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <gradient
    android:startColor="#00ff00"
    android:endColor="#99ff99"
    android:angle="90"/>
   <corners
    android:radius="0dp"/>
 </shape>

Sample output which has multiple screen support:具有多屏幕支持的示例输出:

在此处输入图片说明

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

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