SplashScreen与矢量拉伸全屏 [英] SplashScreen with Vector stretched full screen

查看:157
本文介绍了SplashScreen与矢量拉伸全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本教程中做了启动画面,效果很好:

I did my splash screen with this tutorial and it works great:

基本上,我通过主题设置了幕布:

Basically I set up a splascreen through theme:

<style name="ThemeSplash" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/drawable_splashcreen</item>
</style>

我想在其中放入矢量图像:(drawable_splashcreen)

I wanted to put a vector image inside like this: (drawable_splashcreen)

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/color_background_splash_screen" />
    <item android:drawable="@drawable/vector_najdiflet_logo" />
</layer-list>

图像将全屏拉伸.在API 23上,它应具有应有的功能.但是,在较旧的设备上,它只会出现问题.我尝试了宽度,高度,甚至弄乱了视口,但没有成功.

The image will streched through the full screen. On API 23 it works like it should have. But on older devices it just streches. I tried width, height and even messed up with viewports but no success.

推荐答案

我偶然发现了同样的问题. 不幸的是,似乎没有可能仅使用可用于pre API 23的矢量绘制启动画面.

I stumbled upon the same problem. Unfortunately there does not seem to be a possibility to make the splash screen work with just a vector drawable for pre API 23.

问题是您无法在进程外部加载VectorDrawableCompat,例如在本例中的主题android:windowBackground中.因此,这里可能发生的事情是,在API 21上,将Vector转换为兼容的PNG.因此,在<layered-list>中,将转换后的PNG插入到<item>元素中,这导致位图扩展到所有边缘,因为它缺少<bitmap>元素.

The problem is you can't load VectorDrawableCompat outside of the process, like in this case in your themes android:windowBackground. So what is likely happening here is, that on API 21 the Vector get's converted to a PNG to be compatible. So in the <layered-list>the converted PNG is inserted into the <item> element, which causes the bitmap to stretch to all edges, because it's missing the <bitmap> element.

所以我的解决方法如下:在文件夹drawables-v23内创建一个drawable_splashscreen.xml,它类似于矢量可绘制对象的以下内容.

So my solution is the following: Create a drawable_splashscreen.xml inside the folder drawables-v23 which looks like the following for the vector drawable.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:opacity="opaque">
    <item android:drawable="?attr/colorPrimary"/>
    <item android:drawable="@drawable/ic_splashscreen" android:gravity="center"/>
</layer-list>

然后在常规drawables文件夹中创建另一个drawable_splashscreen.xml:

Then create another drawable_splashscreen.xml but inside the regular drawables folder:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:opacity="opaque">
    <item android:drawable="?attr/colorPrimary"/>
    <item>
        <bitmap android:src="@drawable/ic_splashscreen" android:gravity="center"/>
    </item>
</layer-list>

注意<bitmap>元素.因此,现在,当在API 23之前的设备上使用PNG时,它将正确显示,并且不会延伸到整个背景.

Notice the <bitmap> element. So now, when the PNG is used on pre API 23 devices it will be displayed properly and won't be stretched to the whole background.

不幸的是,您还必须提供启动屏幕作为PNG,才能在旧的API中工作.

Unfortunately you also have to provide splash screen as PNG for this to work in the old APIs.

但是对于具有API 23+的每台设备,都会使用vector drawable.

But for every device with API 23+ the vector drawable will be used.

这篇关于SplashScreen与矢量拉伸全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆