0

I have an imageview that I want to animate (just enlarge it) with an Animation. My XML code for the animation:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator" >

<scale
    android:duration="1000"
    android:fillBefore="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:toXScale="3.0"
    android:toYScale="3.0" />

</set>

And in my Activity:

createAnims();
playButton.startAnimation(animPlay1);

Where the createAnims() method does this:

animPlay1 = AnimationUtils.loadAnimation(this, R.anim.playbut_scaleup);
animPlay1.setRepeatCount(2);
animPlay1.start();

The image is showing but the animation is not working. (The ImageView is called playButton)

4

1 回答 1

2

试试这个代码,它可以帮助你......;)

public class MainActivity extends Activity {
private ImageView mImageView;
private Button mAnimButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test3_main_activity);

    mImageView = (ImageView) findViewById(R.id.ImageView);
    mAnimButton = (Button) findViewById(R.id.AnimationButton);
    mAnimButton.setOnClickListener(mClickListener);
}

private View.OnClickListener mClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mImageView.startAnimation(getAnimation());
    }
};

private Animation getAnimation(){
    ScaleAnimation animation = new ScaleAnimation(1, 3, 1, 3);
    animation.setDuration(1000);
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.REVERSE);
    return animation;
}
}

试试这个 XML,它会工作......

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<scale
    android:duration="1000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toXScale="3"
    android:toYScale="3" />

</set>
于 2013-10-08T07:39:52.747 回答