请解释我如何解决它?我加载矢量可绘制调用VectorDrawableCompat.create(context.getResources(), resId, context.getTheme());
它适用于所有支持的设备(从 API 8 开始),但绘制所有带有位移的图标。为什么?我无法理解。例如,它的NavigationView
菜单:
布局边界:
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
dependencies {
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
示例VectorDrawable
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19,3h-1L18,1h-2v2L8,3L8,1L6,1v2L5,3c-1.11,0 -1.99,0.9 -1.99,2L3,19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,19L5,19L5,8h14v11zM7,10h5v5L7,15z"/>
</vector>
PS 我在带有软件渲染的 Android 6.0 模拟器上制作了这个截图(Ubuntu 16.04 和 radeon HD 5xxx,我很幸运)。不幸的是,我没有真正的设备所以...可能是由于软件渲染?