【发布时间】:2016-06-23 19:16:49
【问题描述】:
我正在尝试创建一个挥动 Android 机器人徽标的简单动画。我的VectorDrawable 和AnimatedVectorDrawable 定义如下:
VectorDrawable (drawable/android.xml)
<vector android:height="240dp" android:viewportHeight="345.0"
android:viewportWidth="294.0" android:width="240dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#a4c639"
android:pathData="M206.62,4.72L206.62,4.72A6.5,6.5 57.81,0 1,209.16 13.56L173.77,77.4A6.5,6.5 76.8,0 1,164.93 79.94L164.93,79.94A6.5,6.5 76.8,0 1,162.4 71.1L197.79,7.26A6.5,6.5 57.81,0 1,206.62 4.72z"
android:strokeColor="#FFF" android:strokeWidth="1"/>
<path android:fillColor="#a4c639"
android:pathData="M74.07,7.53L74.07,7.53A6.5,6.5 112,0 1,82.9 10.06L118.29,73.91A6.5,6.5 124.14,0 1,115.76 82.74L115.76,82.74A6.5,6.5 124.14,0 1,106.92 80.21L71.53,16.36A6.5,6.5 112,0 1,74.07 7.53z"
android:strokeColor="#FFF" android:strokeWidth="1"/>
<path
android:name="leftArm"
android:fillColor="#ff0000"
android:pathData="M28,111L28,111A24,24 0,0 1,52 135L52,220A24,24 0,0 1,28 244L28,244A24,24 0,0 1,4 220L4,135A24,24 0,0 1,28 111z"
/>
<path android:fillColor="#a4c639" android:pathData="M56,111a91,84 0,1 0,182 0a91,84 0,1 0,-182 0z"/>
<path android:fillColor="#a4c639" android:pathData="M78,90L216,90A22,22 0,0 1,238 112L238,250A22,22 0,0 1,216 272L78,272A22,22 0,0 1,56 250L56,112A22,22 0,0 1,78 90z"/>
<path
android:name="rightArm"
android:fillColor="#00f"
android:pathData="M264,111L264,111A24,24 0,0 1,288 135L288,220A24,24 0,0 1,264 244L264,244A24,24 0,0 1,240 220L240,135A24,24 0,0 1,264 111z"/>
<path android:fillColor="#FFF" android:pathData="m52,114.5h190"
android:strokeColor="#FFF" android:strokeWidth="1"/>
<path android:fillColor="#FFF"
android:pathData="M105,70m-4,0a4,4 0,1 1,8 0a4,4 0,1 1,-8 0"
android:strokeColor="#FFF" android:strokeWidth="1"/>
<path android:fillColor="#FFF"
android:pathData="M189,70m-4,0a4,4 0,1 1,8 0a4,4 0,1 1,-8 0"
android:strokeColor="#FFF" android:strokeWidth="1"/>
</vector>
AnimatedVectorDrawable (drawable/wave.xml)
<?xml version="1.0" encoding="utf-8"?>
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/android">
<target
android:animation="@animator/waveanim"
android:name="leftArm"/>
</animated-vector>
这里是 animator/waveanim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:repeatCount="1"
android:repeatMode="reverse"
android:propertyName="pivotX"
android:valueFrom="0.0"
android:valueTo="50.0"
/>
</set>
我之前尝试过一些不同的事情,例如将“leftArm”路径包装在<group> 中并尝试为随机属性设置动画。我能够获得一些随机动作,但与我想要的完全不同,所以我放弃了该代码并回到开头。
顺便说一句,这是它目前的样子:
那么我怎样才能让手臂向我挥动呢?
【问题讨论】:
标签: android android-animation android-drawable android-vectordrawable