我有一个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>
代码没有什么,仅仅是模板代码。
我使用Android Studio的矢量导入向其中添加了一个svg。
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上看起来像这样:
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>
或者,我尝试了this svg,甚至使它适合整个手机屏幕,而且它从未变得模糊。
那么我的svg有什么问题?我有很多相同问题的svg,大多数以相同的方式生成。
编辑:看来问题在于渐变。如果我把它取出来就可以了。除非有人有更好的解释,否则会提交错误吗?