我想动画几行轨道上的按钮...... 例如,我想要将按钮从点A(0,0)设置为点B(100,100),然后从B设置为C(200,0)。 问题在于我这样做的方式,在A - > B和B - > C动画之间,我的视图表现得非常奇怪,它无缘无故地在B位置周围振动。为什么会这样?
另一个问题是,当我为A到B的按钮设置动画时,此路线中的速度会发生变化。我怎么解决这个问题?
这是我的代码:
import android.view.animation.Animation;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.TranslateAnimation;
public class LinearAnimation {
public Animation fromAtoB(float fromX, float fromY, float toX, float toY, Animation.AnimationListener l, int speed){
Animation fromAtoB = new TranslateAnimation(
Animation.ABSOLUTE, //from xType
fromX,
Animation.ABSOLUTE, //to xType
toX,
Animation.ABSOLUTE, //from yType
fromY,
Animation.ABSOLUTE, //to yType
toY
);
fromAtoB.setDuration(speed);
fromAtoB.setInterpolator(new AnticipateOvershootInterpolator(1.0f));
if(l != null)
fromAtoB.setAnimationListener(l);
return fromAtoB;
}
}
和
Animation.AnimationListener animL = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
btn.clearAnimation();
/*rl=new RelativeLayout.LayoutParams(40,40);
rl.leftMargin=DataBase.endX-(int)(btn.getWidth()/2);
rl.topMargin=DataBase.endY-(int)(btn.getHeight()/2);
btn.setLayoutParams(rl);*/
if (DataBase.endX>=DataBase.Layout_Width+40)
{
System.out.println("FINISHED");
btn.setVisibility(View.GONE);
stopLooping=true;
}
else
{
setCoordinates();
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
};
LinearAnimation anim = new LinearAnimation();
System.out.println(DataBase.startX+" "+ DataBase.startY+" "+DataBase.endX+" "+DataBase.endY+" "+negative);
Animation a = anim.fromAtoB(DataBase.startX, DataBase.startY, DataBase.endX, DataBase.endY, animL,5000);
a.setFillAfter(false);
btn.setAnimation(a);
}
答案 0 :(得分:0)
不要在动画上使用AnticipateOvershootInterpolator
请改用AccelerateDecelerateInterpolator
。