升级到3.0后,Android Studio开始抱怨矢量绘图中的长路径.
警告说:
很长的矢量路径(7958个字符),这对性能不利.考虑降低精度,删除次要细节或光栅化矢量.less ...(⌘F1)使用长向量路径对性能不利.有几种方法可以缩短pathData:*使用较少的精度*删除一些细节*使用Android Studio矢量转换工具*光栅化图像(转换为PNG)
文档https://developer.android.com/guide/topics/graphics/vector-drawable-resources.html向我们展示了如何在我们的应用程序中使用矢量绘图,并通过png等推荐它.
我一直在使用Android Studio矢量转换工具和这个优秀的服务将SVG转换为矢量绘图:http: //inloop.github.io/svg2android/
是否还有其他服务可以减少矢量可绘制的复杂性?我在哪里可以找到关于我的矢量绘图可以"先进"的指导方针?
我"ERROR@ <mask> is not supported"尝试使用导入SVG时收到消息
 Android Studio 3.0.1
Build #AI-171.4443003, built on November 10, 2017
JRE: 1.8.0_152-release-915-b08 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6
无论如何导入SVG并使它们正确显示?
我试图实现变形效果,当用户点击myButton时,ImageView内的图像应该从箭头变为复选标记.当他再次点击它时,该过程应该反转:复选标记应变为箭头.
这就是我所做的:
animated_vector.xml:
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/vector_upvote">
    <target
        android:name="rotationGroup"
        android:animation="@anim/rotate_a_to_b" />
    <target
        android:name="upvote"
        android:animation="@animator/animator_upvote_to_checkmark" />
</animated-vector>
animator_upvote_to_checkmark.xml:
<objectAnimator
    android:duration="250"
    android:propertyName="pathData"
    android:valueFrom="@string/svg_upvote"
    android:valueTo="@string/svg_checkmark"
    android:valueType="pathType"
    android:repeatMode="reverse" />
这就是我播放动画的方式:
            Drawable drawable = upVote.getDrawable();
            if (drawable instanceof Animatable) {
                ((Animatable) drawable).start();
            }
这会将箭头变为复选标记,如何反转过程?
我一直在使用Android Asset Studio从Zeplin导出的SVG文件生成矢量drawables一段时间,除了几次,它工作正常.但是今天我尝试使用生成的矢量drawable时遇到了这个异常.
android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
并在相同的堆栈跟踪中:
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid drawable tag gradient
我对Android中的Vector drawables和SVG知之甚少.Vector drawables中是否不支持渐变?是否有解决此问题的方法,还是需要使用PNG?
我使用支持库版本:
com.android.support:support-v4:26.1.0
我在用
Android Studio 3.0
以下是Android Asset Studio生成的VectorDrawable文件:
<vector 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="360dp"
    android:height="110dp"
    android:viewportWidth="360.0"
    android:viewportHeight="110.0">
    <path
        android:pathData="M82,46H0v64h360V46h-81.88v-0.3h-26.21c-14.25,0 -38.69,-6.2 -46.95,-25.93C200.99,10.25 193.27,0.52 180,0.47c-13.27,-0.05 -20.04,9.24 -24.75,19.3 -8.22,17.55 -24.66,26.19 -49.34,25.93H82V46z"
        android:fillType="evenOdd">
        <aapt:attr name="android:fillColor">
            <gradient 
                android:startY="0.41999998688697815" 
                android:startX="0.0" 
                android:endY="110.0" 
                android:type="linear" 
                android:endX="360.0">
                <item android:offset="0.0" android:color="#FFCB09FF" />
                <item android:offset="1.0" android:color="#FF8A06FF" />
            </gradient>
        </aapt:attr></path>
</vector>
链接到原始SVG文件:https://drive.google.com/file/d/1Lj62xJv5IpYR5Lle7w1kMsFXh6y5PijK/view? …
我试图让动画vectorDrawables工作,并根据http://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html做了一切,它仍然无法正常工作.
我也试图让这个项目有效. https://github.com/chiuki/animated-vector-drawable
有谁知道它为什么没有动画?
这是我使用的文件:
AnimatedVectorDrawable
<animated-vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/circle">
?
    <target
        android:name="circle"
        android:animation="@anim/morph_to_drop"/>
?
</animated-vector>
VectorDrawable
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="80dp"
        android:height="80dp"
        android:viewportHeight="50"
        android:viewportWidth="50">
?
    <path
        android:name="circle"
        android:fillColor="#607eff"
        android:pathData="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -7.124,16.015 -15.9,16.015c-8.775,0
-15.9,-7.239 -15.9,-16.015c0,-8.775 7.125,-15.9 15.9,-15.9Z"/>
?
</vector>
动画师(morph_to_drop)
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:duration="1000"
        android:propertyName="pathData"
        android:valueFrom="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -7.124,16.015 -15.9,16.015c-8.775,0
-15.9,-7.239 -15.9,-16.015c0,-8.775 7.125,-15.9 15.9,-15.9Z"
        android:valueTo="M15.9,0c8.776,0 15.9,7.125 15.9,15.9c0,8.776 -12.626,30.167
-15.707,30.143c-3.08,-0.024 -16.093,-21.367 -16.093,-30.143c0,-8.775 7.125,-15.9
15.9,-15.9Z"
        android:valueType="pathType"/>
</set>
主要布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
?
    <ImageView
        android:id="@+id/testImage" …| 尝试从AndroidStudio 2.2,Ubuntu 14.04的本地svg文件生成矢量资产时出现此错误
Could not generate a preview
In icon.svg
ERROR@ line 6 <defs> is not supported
ERROR@ line 25 <use> is not supported
我谷歌发现发生的事情是因为AndroidStudio不支持<defs>,<use>... 
但我不知道如何修复它?
我可以更改<defs>为AndroidStudio支持的另一个标签吗?
或者我永远不能从这个SVG文件生成矢量资产?
任何帮助或建议将非常感谢.
我编写了一个带有自定义属性的自定义复合视图.其中一个自定义属性是drawable,我希望使用的文件是Vector Drawable.
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0)
val iconDrawable = typedArray.getDrawable(R.styleable.CustomView_icon_drawable)
我一直得到一个XmlPullParserException:二进制XML文件行#1:无效的drawable标签向量
为什么是这样?
这是我的build.gradle
    defaultConfig {
    ...
    minSdkVersion 21
    targetSdkVersion 26
    vectorDrawables.useSupportLibrary = true
}
和布局的一部分
<ImageView
    android:id="@+id/recents"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    android:clickable="true"
    android:scaleType="fitCenter"
    app:srcCompat="@drawable/anim_test"/>
和类演员:
val np = convertView.findViewById<ImageView>(R.id.recents)
val anim = np.drawable as AnimatedVectorDrawableCompat
这在Lolipop(sdk 21)上按预期工作,但在Nougat上失败说:
android.graphics.drawable.AnimatedVectorDrawable cannot be cast to android.support.graphics.drawable.AnimatedVectorDrawableCompat
我没有得到的是,为什么当系统已经支持AnimatedVectorDrawable时,它在sdk级别21上返回AnimatedVectorDrawableCompat.为什么它会在Nougat中返回AnimatedVectorDrawable而不管指定vectorDrawables.useSupportLibrary = true.
我想将SVG文件转换为Android Vector Drawable XML.我需要SVG的结构.在SVG将多个元素组合在一起的范围内,我需要将该分组也反映在Android Vector Drawable中.
不幸的是,我发现做SVG到Vector Drawable转换的工具试图以一种摆脱文件结构中现有分组的方式最小化文件大小.
是否有一种聪明的方法来进行转换,使分组树保持完整?
我想在我的启动画面中显示一个 VectorDrawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@android:color/white"
        android:gravity="fill" />
    <item
        android:drawable="@drawable/splash_screen"
        android:gravity="bottom|center" />
</layer-list>
我的 SVG 有android:width="320dp"和android:height="238dp"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="320dp"
    android:height="238dp"
    android:viewportWidth="320"
    android:viewportHeight="238">
  <group>
    <clip-path android:pathData="M0,0h320v238h-320z M 0,0"/>
    <path
        android:pathData="M0,143.311a160,4.476 0,1 0,320 0a160,4.476 0,1 0,-320 0z"
        android:fillColor="#E6E6E6"/>
    <path
        android:pathData="M245.269,94.815C245.067,94.818 244.865,94.821 244.66,94.821C244.455,94.821 244.253,94.818 244.051,94.815C233.341,94.572 225.578,87.88 227.554,80.859L232.372,63.73L233.59,59.396L255.177,59.764L256.488,64.004L261.653,80.693C263.839,87.753 256.076,94.572 245.269,94.815Z"
        android:fillColor="#3F3D56"/>
    <path
        android:pathData="M256.488,64.004C248.993,68.288 239.768,68.184 232.372,63.73L233.59,59.396L255.177,59.764L256.488,64.004Z"
        android:strokeAlpha="0.2"
        android:fillColor="#000000"
        android:fillAlpha="0.2"/>
    <path
        android:pathData="M255.577,81.427C256.51,77.952 259.575,72.938 268.17,66.893C283.16,56.35 274.218,48.444 273.83,48.113C273.017,47.418 273.137,46.638 274.109,46.371C275.252,46.143 276.437,46.419 277.361,47.128C277.846,47.529 289.044,57.092 272.129,68.988C256.906,79.695 260.142,86.685 260.179,86.752C260.587,87.499 259.933,88.097 258.717,88.089C257.501,88.081 256.183,87.469 255.774,86.723C255.688,86.565 254.709,84.662 255.577,81.427Z" …