Reputation: 4222
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)
Upvotes: 0
Views: 78
Reputation: 7071
Try this code, It may help you...;)
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;
}
}
Try this XML, It will work...
<?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>
Upvotes: 2