首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >API 25中的矢量动画

API 25中的矢量动画
EN

Stack Overflow用户
提问于 2016-12-05 14:22:27
回答 1查看 404关注 0票数 0

我有矢量绘图动画。它在API 17-24中工作正常,但在API 25中有问题。动画运行,但向量按不同的顺序移动。

这是我的矢量可绘制

代码语言:javascript
运行
复制
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
                 android:drawable="@drawable/logo_vector_white">
    <target
        android:name="eye"
        android:animation="@animator/blink_eye" />
</animated-vector>

这是动画

代码语言:javascript
运行
复制
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:duration="300"
        android:propertyName="scaleX"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:valueTo="0.05"
        android:valueType="floatType"/>
    <objectAnimator
        android:duration="300"
        android:propertyName="translateX"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:valueTo="155"
        android:valueType="floatType"/>
</set>

下面是我运行它的方式

代码语言:javascript
运行
复制
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Drawable animation = logo.getDrawable();
                if (animation instanceof Animatable) {
                    ((Animatable) animation).start();
                }
            }
        }, 300);

我发现,从API 25开始,AnimatedVectorDrawable 在RenderThread上运行。如果这引起了问题,该如何解决呢?我还试图将所有动画文件绑定到单个xml中,但结果是相同的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-14 10:25:24

我只需要做我的矢量对象的水平比例动画(它是闪烁的眼睛,以X到0的比例,然后返回到以前的状态)。我不知道枢轴,我又用了一个translateX动画来补偿矢量的水平运动。这个解决方案一直工作到API 25,当它开始在RenderThread上执行时。

修正方法是将android:透视X添加到组中,并删除带有translateX属性的translateX。还添加了android:valueFrom="1“(在API 25动画上没有它就立即切换到valueTo )。

这是完整的xml。

代码语言:javascript
运行
复制
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
                 xmlns:aapt="http://schemas.android.com/aapt"
                 xmlns:tools="http://schemas.android.com/tools"
                 tools:ignore="MissingPrefix">

    <aapt:attr name="android:drawable">
        <vector xmlns:android="http://schemas.android.com/apk/res/android"
                android:width="292dp"
                android:height="108dp"
                android:viewportHeight="108.0"
                android:viewportWidth="292.0">
            <path
                android:fillColor="#FFFFFF"
                android:pathData="M7,12L93,12A7,7 0,0 1,100 19L100,34A7,7 0,0 1,93 41L7,41A7,7 0,0 1,0 34L0,19A7,7 0,0 1,7 12z"
                android:strokeColor="#00000000"
                android:strokeWidth="1"/>

            <group
                android:name="eye"
                android:pivotX="160">
                <path
                    android:name="right_eye"
                    android:fillColor="#FFFFFF"
                    android:pathData="M161.5,26.5m-16.5,0a16.5,16.5 0,1 1,33 0a16.5,16.5 0,1 1,-33 0"
                    android:strokeColor="#00000000"
                    android:strokeWidth="1"/>
            </group>

            <path
                android:fillColor="#FFFFFF"
                android:pathData="M7,67L93,67A7,7 0,0 1,100 74L100,89A7,7 0,0 1,93 96L7,96A7,7 0,0 1,0 89L0,74A7,7 0,0 1,7 67z"
                android:strokeColor="#00000000"
                android:strokeWidth="1"/>
            <path
                android:name="left_eye"
                android:fillColor="#FFFFFF"
                android:pathData="M161.5,81.5m-16.5,0a16.5,16.5 0,1 1,33 0a16.5,16.5 1,1 1,-33 0"
                android:strokeColor="#00000000"
                android:strokeWidth="1"/>
            <path
                android:fillColor="#FFFFFF"
                android:pathData="M241.46,1.54L289.96,50.04A5,5 119.52,0 1,289.96 57.11L278.07,69A5,5 0,0 1,271 69L222.5,20.5A5,5 57.75,0 1,222.5 13.43L234.39,1.54A5,5 86.11,0 1,241.46 1.54z"
                android:strokeColor="#00000000"
                android:strokeWidth="1"/>
            <path
                android:fillColor="#FFFFFF"
                android:pathData="M241.5,106L290,57.5A5,5 60.48,0 0,290 50.43L278.11,38.54A5,5 0,0 0,271.04 38.54L222.54,87.04A5,5 112.86,0 0,222.54 94.11L234.43,106A5,5 0,0 0,241.5 106z"
                android:strokeColor="#00000000"
                android:strokeWidth="1"/>
        </vector>
    </aapt:attr>

    <target android:name="eye">
        <aapt:attr name="android:animation">
                <objectAnimator
                    android:duration="300"
                    android:propertyName="scaleX"
                    android:repeatCount="1"
                    android:repeatMode="reverse"
                    android:valueFrom="1"
                    android:valueTo="0"
                    android:valueType="floatType"/>
        </aapt:attr>
    </target>

</animated-vector>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40976459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档