Android:使用搜索栏为动画矢量绘制动画

问题描述 投票:1回答:2

我是两年以来的Android开发者,但我从未使用过动画。我有一个问题要为我的公司解决:我需要画一个悲伤的笑脸,让他更快乐,因为提高了搜索栏的价值,如下图所示。

Smile following the progress of a seek bar

为了绘制微笑动画我遵循关于AnimatedVectorDrawable的android文档

但现在动画的持续时间为3000毫秒,我想用搜索条控制动画(如视频)。

真的试图在三天内通过互联网找到一些东西,但我想我没有找到我想要的关键词。

我的动画矢量:

<animated-vector 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/face" >
    <target
      android:name="mouth"
      android:animation="@animator/smile" />
</animated-vector>

我的矢量

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="200dp"
    android:width="200dp"
    android:viewportHeight="100"
    android:viewportWidth="100" >
  <path
    android:fillColor="@color/yellow"
    android:pathData="@string/path_circle"/>
  <path
    android:fillColor="@android:color/black"
    android:pathData="@string/path_face_left_eye"/>
  <path
    android:fillColor="@android:color/black"
    android:pathData="@string/path_face_right_eye"/>
  <path
    android:name="mouth"
    android:strokeColor="@android:color/black"
    android:strokeWidth="@integer/stroke_width"
    android:strokeLineCap="round"
    android:pathData="@string/path_face_mouth_sad"/>
</vector>

我的对象动画师

<objectAnimator
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:duration="3000"
  android:propertyName="pathData"
  android:valueFrom="@string/path_face_mouth_sad"
  android:valueTo="@string/path_face_mouth_happy"
  android:valueType="pathType"
  android:interpolator="@android:anim/accelerate_interpolator"/>

我的动画功能

private void animate() {
  Drawable drawable = imageView.getDrawable();
  if (drawable instanceof Animatable) {
    ((AnimatedVectorDrawable) drawable).start();
  }
}

谢谢您帮忙。如果您需要有关我尝试的更多信息,请不要犹豫。

android animation view seekbar android-vectordrawable
2个回答
1
投票

您应该查看RoadRunner,它适用于SVG并允许您手动设置进度。


0
投票

使用ValueAnimator:

ValueAnimator mProgressAnimator = ValueAnimator.ofInt(progress, 
getMax()).setDuration(timeToEnd);
mProgressAnimator.setInterpolator(new LinearInterpolator());
mProgressAnimator.addUpdateListener(this);
mProgressAnimator.start();

@Override
public void onAnimationUpdate(final ValueAnimator valueAnimator) {
    final int animatedIntValue = (int) 
    valueAnimator.getAnimatedValue();
    setProgress(animatedIntValue);
}
© www.soinside.com 2019 - 2024. All rights reserved.