Некоторые SVG размыты под Android 5, но другие работают нормально - PullRequest
0 голосов
/ 08 сентября 2018

У меня есть пример приложения для Android, очень простое, только что сделанное из шаблонов.

Это макет:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
    <android.support.v7.widget.AppCompatImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:scaleType="fitXY"
        app:srcCompat="@drawable/ic_group2s"
        />
</android.support.constraint.ConstraintLayout>

В коде ничего нет, это просто код шаблона.

Я добавил svg, используя векторный импорт Android Studio.

Файл Gradle выглядит так:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.instantbits.svgtest"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Вопрос? простой SVG, который я импортировал, выглядит на Android P следующим образом: enter image description here

А на Android 5 это выглядит так: enter image description here

SVG это:

<svg width="55" height="49" viewBox="0 0 55 49" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10.2378 22.7434H45.2609L46.5951 48.2018H8.23651L10.2378 22.7434Z" fill="#8561C5"/>
<path d="M6.04576 10.0445H50.5813L52.2779 43.0081H3.50087L6.04576 10.0445Z" fill="#B39CDB"/>
<path d="M3.23464 0.347839H52.9587L54.853 36.6496H0.393265L3.23464 0.347839Z" fill="url(#paint0_linear)"/>
<ellipse cx="27.8599" cy="17.7915" rx="14.2069" ry="14.1435" fill="#4527A0"/>
<path d="M23.1243 23.6847V11.8984L34.7266 17.0843L23.1243 23.6847Z" fill="white"/>
<defs>
<linearGradient id="paint0_linear" x1="29.1991" y1="64.7127" x2="28.5752" y2="9.79314" gradientUnits="userSpaceOnUse">
<stop stop-color="#4527A0"/>
<stop offset="1" stop-color="white"/>
</linearGradient>
</defs>
</svg>

импортированный вектор выглядит так:

<vector android:height="24dp" android:viewportHeight="49"
    android:viewportWidth="55" android:width="24dp"
    xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#8561C5" android:pathData="M10.2378,22.7434H45.2609L46.5951,48.2018H8.2365L10.2378,22.7434Z"/>
    <path android:fillColor="#B39CDB" android:pathData="M6.0458,10.0445H50.5813L52.2779,43.0081H3.5009L6.0458,10.0445Z"/>
    <path android:pathData="M3.2346,0.3478H52.9587L54.853,36.6496H0.3933L3.2346,0.3478Z">
        <aapt:attr name="android:fillColor">
            <gradient android:endX="28.5752" android:endY="9.79314"
                android:startX="29.1991" android:startY="64.7127" android:type="linear">
                <item android:color="#FF4527A0" android:offset="0"/>
                <item android:color="#FFFFFFFF" android:offset="1"/>
            </gradient>
        </aapt:attr>
    </path>
    <path android:fillColor="#4527A0" android:pathData="M13.653,17.7915a14.2069,14.1435 0,1 0,28.4138 0a14.2069,14.1435 0,1 0,-28.4138 0z"/>
    <path android:fillColor="#ffffff" android:pathData="M23.1243,23.6847V11.8984L34.7266,17.0843L23.1243,23.6847Z"/>
</vector>

В качестве альтернативы я попробовал этот svg и даже сделал так, чтобы он уместился на весь экран телефона, и он никогда не становился размытым.

Так в чем же проблема с моим svg? У меня много svgs с той же проблемой, большинство сгенерировано одинаково.

Редактировать: похоже, проблема в градиенте. Если я возьму это, это работает просто отлично. Собираетесь сообщить об ошибке, если у кого-то нет лучшего объяснения?

...