Android VectorDrawableCompat使用位移绘制图标
请告诉我怎么修?我加载vector drawable调用VectorDrawableCompat.create(context.getResources(),resId,context.getTheme())代码>Android VectorDrawableCompat使用位移绘制图标,android,android-vectordrawable,Android,Android Vectordrawable,请告诉我怎么修?我加载vector drawable调用VectorDrawableCompat.create(context.getResources(),resId,context.getTheme()) 它适用于所有受支持的设备(从API 8开始),但会绘制带有位移的所有图标。为什么?我不明白。例如,它是NavigationView菜单: 布局边界: build.gradle apply plugin: 'com.android.application' android {
它适用于所有受支持的设备(从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'
}
<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>
可矢量绘制的示例
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'
}
<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>
p.S.我在Android 6.0模拟器上用软件渲染(Ubuntu 16.04和radeon HD 5xxx,Imma lucky)制作了这个屏幕截图。不幸的是,我没有真正的设备所以。。。这可能是由于软件渲染造成的吗?1)在模拟器中,转到“设置>开发人员选项>绘图>显示布局边界”。打开它并发布另一个屏幕截图。2) 您正在使用哪个版本的支持库?或post build.gradle文件。3) 你能在
VectorDrawableCompat.create
发布更多的ode吗?你是如何将这个DrawableCompat.create附加到你的视图的?退步?或者作为一个复合的drawable?作为菜单项的setIcon()
,运行并观看logcat,有趣的是,在4.4和5.0上,这两个项都使用了android.support.graphics.drawable.VectorDrawableCompat
,它工作得很好,但在6.0上只有stdVectorDrawable
工作-(更有趣的是,如果你将你的VectorDrawableCompat
包装在另一个Drawable
上,让它成为LayerDrawable、InsertDrawable或support.v7.graphics.Drawable.DrawableWrapper,它就会自动开始工作