文章40 | 阅读 20711 | 点赞0
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:oneshot="false">
<item ohos:element="$media:01" ohos:duration="100"/>
<item ohos:element="$media:02" ohos:duration="100"/>
<item ohos:element="$media:03" ohos:duration="100"/>
<item ohos:element="$media:04" ohos:duration="100"/>
<item ohos:element="$media:05" ohos:duration="100"/>
<item ohos:element="$media:06" ohos:duration="100"/>
<item ohos:element="$media:07" ohos:duration="100"/>
<item ohos:element="$media:08" ohos:duration="100"/>
<item ohos:element="$media:09" ohos:duration="100"/>
<item ohos:element="$media:10" ohos:duration="100"/>
<item ohos:element="$media:11" ohos:duration="100"/>
<item ohos:element="$media:12" ohos:duration="100"/>
</animation-list>
FrameAnimationElement frameAnimationElement = new FrameAnimationElement(getContext(), ResourceTable.Graphic_animation_element);
Component component = new Component(getContext());
component.setWidth(500);
component.setHeight(500);
component.setBackground(frameAnimationElement);
frameAnimationElement.start();
AnimatorValue animatorValue = new AnimatorValue();
<?xml version="1.0" encoding="UTF-8" ?>
<animator xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:delay="1000"
ohos:duration="2000"/>
animatorValue.setDuration(2000);
animatorValue.setDelay(1000);
animatorValue.setLoopedCount(2);
animatorValue.setCurveType(Animator.CurveType.BOUNCE);
AnimatorScatter scatter = AnimatorScatter.getInstance(getContext());
Animator animator = scatter.parse(ResourceTable.Animation_animator_value);
if (animator instanceof AnimatorValue) {
AnimatorValue animatorValue = (AnimatorValue) animator;
animatorValue.setLoopedCount(2);
animatorValue.setCurveType(Animator.CurveType.BOUNCE);
}
animatorValue.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
@Override
public void onUpdate(AnimatorValue animatorValue, float value) {
button.setContentPosition((int) (800 * value), button.getContentPositionY());
}
});
animatorValue.start();
AnimatorProperty animatorProperty = image.createAnimatorProperty();
<?xml version="1.0" encoding="UTF-8" ?>
<animatorProperty xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:delay="500"
ohos:duration="2500"/>
animatorProperty.moveFromX(50).moveToX(1000).rotate(90).alpha(0).setDuration(2500).setDelay(500).setLoopedCount(5);
AnimatorScatter scatter = AnimatorScatter.getInstance(getContext());
Animator animator = scatter.parse(ResourceTable.Animation_animator_property);
if (animator instanceof AnimatorProperty) {
AnimatorProperty animatorProperty = (AnimatorProperty) animator;
animatorProperty.setTarget(component);
animatorProperty.moveFromX(50).moveToX(1000).rotate(90).alpha(0).setLoopedCount(5);
}
image.setBindStateChangedListener(new Component.BindStateChangedListener() {
@Override
public void onComponentBoundToWindow(Component component) {
animatorProperty.start();
}
@Override
public void onComponentUnboundFromWindow(Component component) {
animatorProperty.stop();
}});
image.setClickedListener(component -> animatorProperty.start());
AnimatorGroup animatorGroup = new AnimatorGroup();
// 4个动画按顺序播放
animatorGroup.runSerially(am1, am2, am3, am4);
// 4个动画同时播放
animatorGroup.runParallel(am1, am2, am3, am4);
animatorGroup.start();
AnimatorGroup.Builder animatorGroupBuilder = animatorGroup.build();
// 4个动画的顺序为: am1 -> am2/am3 -> am4
animatorGroupBuilder.addAnimators(am1).addAnimators(am2, am3).addAnimators(am4)
animatorGroup.start();
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/Forever_wj/article/details/118280640
内容来源于网络,如有侵权,请联系作者删除!