- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这是我需要通过AnimatedVectorDrawableCompat
实现的效果。
vector_drawable_anim.xml
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector_drawable">
<target
android:name="star"
android:animation="@animator/star_anim"/>
</animated-vector>
vector_drawable.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="500px"
android:height="500px"
android:viewportHeight="500"
android:viewportWidth="500">
<group
android:name="star_group"
android:scaleX="5.0"
android:scaleY="5.0">
<path
android:name="star"
android:pathData="M 50.0,90.0 L 82.9193546357,27.2774101308 L 12.5993502926,35.8158045183 Z"
android:strokeColor="@color/colorAccent"
android:strokeWidth="1"/>
</group>
</vector>
star_anim.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
<objectAnimator
android:duration="1000"
android:propertyName="trimPathStart"
android:valueFrom="1"
android:valueTo="0"/>
<objectAnimator
android:duration="1000"
android:propertyName="trimPathEnd"
android:valueFrom="1"
android:valueTo="0"/>
</set>
但是AnimatorSet
不能设置repeatMode
。
如果我设置了 objectAnimator
的 repeatMode
,第二个 objectAnimator
将不会显示。
我该怎么办?
最佳答案
如何在线程内循环它直到 ImageView 被销毁?
完美运行的代码示例:
ImageView animatedImageView = (ImageView) findViewById(R.id.iv);
AnimatedVectorDrawableCompat animatedVectorDrawable = (AnimatedVectorDrawableCompat) animatedImageView.getDrawable();
new Thread(new Runnable() {
public void run() {
while (animatedImageView != null) {
try {
animatedImageView.post(new Runnable() {
@Override
public void run() {
animatedVectorDrawable.start();
}
});
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
或者,您可以使用 azizbekian 提到的 registerAnimationCallback(),然后是 this git gist code sample :
import android.app.Activity;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Animatable2;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView iv = (ImageView) findViewById(R.id.pin);
final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) iv.getDrawable();
avd.registerAnimationCallback(new Animatable2.AnimationCallback() {
@Override
public void onAnimationEnd(Drawable drawable) {
avd.start();
}
});
avd.start();
}
}
关于android - 重启 AnimatedVectorDrawableCompat 的 AnimatorSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45275801/
这是我的build.gradle defaultConfig { ... minSdkVersion 21 targetSdkVersion 26 vector
我正在尝试使用 AnimatedVectorDrawableCompat 在我的 Android 应用程序中实现动画,以实现 API >= 21 的兼容性。 我希望动画在 Activity 期间循环播
我有以下动画矢量可绘制对象: 它只是使用旋转动画为风扇设置动画。 我在 ImageView 中设置此图标并控制开始/停止动画调用以下方法(仅在 Lollipop 和 high 中):
这是我需要通过AnimatedVectorDrawableCompat实现的效果。 vector_drawable_anim.xml vector_drawable.xml
此代码适用于 Lollipop: drawable = AppCompatResources.getDrawable(this, R.drawable.list_2_map_animated_vect
我正在为支持 Android API 19-26 的应用程序使用动画矢量可绘制对象。为了重新启动动画(这是一个自定义循环加载动画),我使用 AnimatedVectorDrawable.registe
我是一名优秀的程序员,十分优秀!