我有一个想要使用动画制作动画(只是放大)的imageview。我的XML代码 动画:
<?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>
在我的活动中:
createAnims();
playButton.startAnimation(animPlay1);
createAnims()方法执行此操作:
animPlay1 = AnimationUtils.loadAnimation(this, R.anim.playbut_scaleup);
animPlay1.setRepeatCount(2);
animPlay1.start();
图像正在显示但动画无效。 (ImageView称为playButton)
答案 0 :(得分: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>