1

我有一个ImageView. 我想要:
1 - 缩小视图
2 - 更改图像资源
3 - 缩小视图

我在以下代码部分中尝试了此操作,但这不起作用。它的行为就像第三行不存在。有人可以告诉我我做错了什么吗?

Animation anim = AnimationUtils.loadAnimation(this, R.anim.scale);
Animation animo = AnimationUtils.loadAnimation(this, R.anim.scale_out);
i.startAnimation(anim);
i.setImageResource(R.drawable.logoc);
i.startAnimation(animo);

规模.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0" 
android:toXScale="0.125"
android:fromYScale="1.0" 
android:toYScale="0.125" 
android:pivotX="50%"
android:pivotY="50%" 
android:startOffset="0" 
android:duration="400"
android:fillBefore="true" />

scale_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0" 
android:toXScale="4.0"
android:fromYScale="1" 
android:toYScale="4.0" 
android:startOffset="400" 
android:pivotX="50%"
android:pivotY="50%"
android:duration="800"
 />
4

1 回答 1

2

我认为你应该尝试这样做:

i.startAnimation(anim);
if (anim.hasEnded())
{
    i.setImageResource(R.drawable.logoc);
    i.startAnimation(animo);
}

编辑:

好的,我错了:这有效:

public class MyAnimationListener implements AnimationListener {

        @Override
        public void onAnimationEnd(Animation animation) {
            // TODO Auto-generated method stub

            i.setImageResource(R.drawable.bg);
            i.startAnimation(animo);

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

    }

MyAnimationListener mListener = new MyAnimationListener();
        anim.setAnimationListener(mListener);
        i.startAnimation(anim);
于 2012-12-06T12:55:10.820 回答