android - 显示的启动画面 Logo 质量差

标签 android android-layout svg icons imagemagick

我正在构建一个 Android 应用程序,它有:

启动画面,显示应用程序的标志

什么在起作用:

如果我在 SplashScreenActivity 的布局中设置 ImageView,则屏幕显示得非常好,并且会根据需要转到 FirstActivity。

什么不是:

然而,这不是正确的方法,因为它会在应用程序启动时产生延迟,因为布局正在膨胀。我使用了推荐的方法如下:

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/black" />
    <item
        android:gravity="center">
        <bitmap
            android:src="@drawable/logo"
            android:gravity="center"/>
    </item>
</layer-list>

styles.xml

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

AndroidManifest.xml

<application
    android:theme="@style/Splash">
  • 当我尝试从 mipmap 文件夹设置位图 src 时,它生成了一个小图像。

  • 因为我也有 Logo 的 SVG 文件,所以我尝试使用 Vector Asset 生成可绘制对象,但位图 src 需要图像,应用程序崩溃了。

  • 然后我尝试使用 ImageMagick 和 InkScape 从 SVG 生成 PNG 和其他工具及其推荐的高质量图像选项。

但它仍然不如使用以 Vector Drawable 作为源的 ImageView 清晰,最后我现在想不出任何其他方法。

那么,我怎样才能获得与所有其他应用程序相同的图像质量呢?还有什么方法可以使位图使用 SVG 本身?

最佳答案

@hrk sing 是对的,甚至不必费心尝试正确显示位图。您将始终获得低分辨率图像。你能做的最好的事情就是在 vectr 这样的页面上创建一个 vectordrawable 甚至在线。我所做的是直接在 xml 中简单地缩放 vectordrawable,它最终完美地用于我的初始屏幕

<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>

在上面的代码中,我将我在 640x640 Canvas 上绘制的可绘制对象重新缩放为 240x240。然后我像这样放入我的闪屏可绘制对象中,效果很好:

<?xml version="1.0" encoding="utf-8"?>

<!-- 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>

我的代码实际上只是在下图中绘制三角形,但在这里你可以看到你可以用它实现什么。与我在使用位图时得到的像素化边缘相比,分辨率终于很棒了。

my apps splash screen

关于android - 显示的启动画面 Logo 质量差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51134538/

相关文章:

svg - SVG 字体的新语法是什么?

javascript - D3 : Draw part of interpolated path with dashed stroke

android - 有没有办法克隆 IntelliJ IDEA gradle 项目?

android - 引导完成广播不起作用

java - 是否可以抽象出 XML 代码的重复部分?

android - 如何在android中从手势输入中写入和读取文本?

javascript - 旋转后移动 SVG 元素

Android:可滚动(位图)屏幕

Android 更改 tabview 的文本颜色而不是背景颜色

android - 即使调用了宽度 fill_parent,LinearLayout 也不会填充表格行