2 u011448045 u011448045 于 2014.11.07 17:18 提问

Android 动画效果怎么样叠加效果

我想实现的是,一个控件上面同事拥有两种或者两种以上的动画效果。比如说我给一个ImageView设置了一个移动的动画效果,但是我还想让这个控件在移动的同时进行旋转。这个该怎么做?跪求懂得大神指点

3个回答

Kelley_cfy
Kelley_cfy   2014.11.18 11:36

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.5f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
ra=new RotateAnimation(0f, 1800f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.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就是一系列的动作
Kelley_cfy
Kelley_cfy   2014.11.18 11:39

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进去就行了

Kelley_cfy
Kelley_cfy   2014.11.18 11:40

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" />

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!