在不同视图上一起运行动画
问题描述:
我需要动画2个视图,并且我想要动画一起开始。这里是我的两个动画:在不同视图上一起运行动画
ScaleAnimation scaleAnimation1 = new ScaleAnimation(image.getScaleX(), 1.0f, image.getScaleY(), 1.0f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(300);
scaleAnimation.setFillAfter(true);
scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
image.startAnimation(scaleAnimation);
ScaleAnimation scaleAnimation2 = new ScaleAnimation(logo.getScaleX(), 1.0f, logo.getScaleY(), 1.0f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(300);
scaleAnimation.setFillAfter(true);
scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
logo.startAnimation(scaleAnimation);
我该怎么办?我需要以编程方式进行。
P.S.我没有太多的动画经验。
答
这是给你的样品)
public class AnimationUtils {
public static void applyAnimation(Context context, View view, int animationResource, int animationOffsetMilisec){
Animation anim = android.view.animation.AnimationUtils.loadAnimation(context, animationResource);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setStartOffset(animationOffsetMilisec);
if(view != null) {
view.setAnimation(anim);
view.startAnimation(anim);
}
}
}
animation_tap.xml
必须在res /动画/
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<scale
android:duration="100"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.00"
android:toYScale="0.95"
android:pivotX="50%"
android:pivotY="50%"/>
<scale
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="0.95"
android:toXScale="1.0"
android:toYScale="1.1"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="100"/>
</set>
,现在无论在代码中你可以使用:
AnimationUtils.applyAnimation(context,view1,R.anim.animation_tap,0);
AnimationUtils.applyAnimation(context,view2,R.anim.animation_tap,0);
AnimationUtils.applyAnimation(context,view3,R.anim.animation_tap,0);
//...
看看这个例如:http://cogitolearning.co.uk/?p=1194 –
@ItzikSamara即运行两个动画SIM卡在一个单一的观点上是一致的。我想同时在2个不同的视图上启动2个不同的动画。 –
OK看看这个例子:http://stackoverflow.com/questions/17926117/objectanimator-with-scale-property-makes-bg-black它的ObjectAnimator ..有点不同,但我使用它很好。 –