问题描述
- Android 动画效果怎么样叠加效果
- 我想实现的是,一个控件上面同事拥有两种或者两种以上的动画效果。比如说我给一个ImageView设置了一个移动的动画效果,但是我还想让这个控件在移动的同时进行旋转。这个该怎么做?跪求懂得大神指点
解决方案
AnimationSet as;
Animation bs;
TranslateAnimation ta;
ScaleAnimation sa;
RotateAnimation ra;
AlphaAnimation aa;
ta=new TranslateAnimation(0f 500 0f 550);
sa=new ScaleAnimation(1f 0.5f 1f 0.5fAnimation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
ra=new RotateAnimation(0f 1800fAnimation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
ta.setDuration(2000); ta.setRepeatCount(-1); sa.setDuration(2000); sa.setRepeatCount(-1); ra.setRepeatCount(-1); ra.setDuration(2000); bs=AnimationUtils.loadAnimation(this R.layout.animation); as.setDuration(2000); as.setRepeatCount(-1);as.addAnimation(sa); as.addAnimation(ra); as.addAnimation(ta);然后用view.startAnimation(as)就行了,AnimationSet就是一系列的动作
解决方案二:
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"">
android:fromXScale=""1""
android:toXScale=""0.5""
android:fromYScale=""1""
android:toYScale=""0.5""
android:pivotX=""50%""
android:pivotY=""50%""
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"" />
android:fromDegrees=""0""
android:toDegrees=""2160""
android:toYScale=""0.0""
android:pivotX=""50%""
android:pivotY=""50%""
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"" />
android:fromXDelta=""0""
android:toXDelta=""-500""
android:fromYDelta=""0""
android:toYDelta=""550""
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"" />
或者这样,用XML文件定义动画,多种动画时注意将平移动画放在最后
AnimationSet bs=AnimationUtils.loadAnimation(this R.layout.animation);
这样load进去就行了
解决方案三:
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"">
android:fromXScale=""1""
android:toXScale=""0.5""
android:fromYScale=""1""
android:toYScale=""0.5""
android:pivotX=""50%""
android:pivotY=""50%""
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"" />
android:fromDegrees=""0""
android:toDegrees=""2160""
android:toYScale=""0.0""
android:pivotX=""50%""
android:pivotY=""50%""
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"" />
android:fromXDelta=""0""
android:toXDelta=""-500""
android:fromYDelta=""0""
android:toYDelta=""550""
android:duration=""2000""
android:repeatCount=""-1""
android:interpolator=""@android:anim/bounce_interpolator"" />