在这个简单的动画中我希望在完成移动小部件后,停止动画并移动其他小部件,所有动画都必须在完成后停止并且不要递归以前的状态
向上移动xml:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="1000"
android:fromYDelta="0%"
android:toYDelta="-100%" />
</set>
向下移动xml:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="1000"
android:fromYDelta="-100%"
android:toYDelta="0%" />
</set>
我的代码:
public class ActivitySmsReceiveSlave extends Activity implements AnimationListener {
private Animation animMoveUp;
private Animation animMoveDown;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms_receive_slave_view);
G.currentActivity = this;
animMoveUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation_move_up);
animMoveUp.setAnimationListener(this);
animMoveDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation_move_up);
detaileLinearLayout.startAnimation(animMoveUp);
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if (animation == animMoveUp) {
testLinear.startAnimation(animMoveDown);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
在我的xml动画和代码中,完成向上移动或向下移动动画后,小部件递归启动状态和testLinear
小部件不会开始动画
答案 0 :(得分:-1)
package com.example.testmove;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class MainActivity extends Activity implements AnimationListener {
private Animation animMoveUp;
private Animation animMoveDown;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img=(ImageView)findViewById(R.id.imageView1);
animMoveUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.movedown);
animMoveUp.setAnimationListener(this);
animMoveDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.moveup);
animMoveDown.setAnimationListener(this);
img.startAnimation(animMoveUp);
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if (animation == animMoveUp) {
img.startAnimation(animMoveDown);
}
if(animation == animMoveDown){
img.setAnimation(null); }
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}