我有一个代表点的图像视图,我使用4个不同的翻译动画来移动它通过屏幕。它的效果非常好,除了每次应用新动画时,它都从图像视图的原始位置开始,而不是前一个动画放置它的最后位置。知道为什么吗?
这是我配置动画的snipet:
public void initializeDotsAnimation(){
mDotAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,
Animation.RELATIVE_TO_PARENT,-0.28f,Animation.RELATIVE_TO_SELF,0.0f
,Animation.RELATIVE_TO_PARENT,-0.28f);
mDotAnimation.setDuration(500);
mDotAnimation.setFillAfter(true);
mDotAnimation1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,
Animation.RELATIVE_TO_PARENT,-0.21f,Animation.RELATIVE_TO_SELF,0.0f
,Animation.RELATIVE_TO_PARENT,-0.21f);
mDotAnimation1.setDuration(500);
mDotAnimation1.setFillAfter(true);
mDotAnimation2 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,
Animation.RELATIVE_TO_PARENT,-0.13f,Animation.RELATIVE_TO_SELF,0.0f
,Animation.RELATIVE_TO_PARENT,-0.13f);
mDotAnimation2.setDuration(500);
mDotAnimation2.setFillAfter(true);
mDotAnimation3 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,
Animation.RELATIVE_TO_PARENT,-0.08f,Animation.RELATIVE_TO_SELF,0.0f
,Animation.RELATIVE_TO_PARENT,-0.08f);
mDotAnimation3.setDuration(500);
mDotAnimation3.setFillAfter(true);
mDotAnimation4 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,
Animation.RELATIVE_TO_PARENT,-0.02f,Animation.RELATIVE_TO_SELF,0.0f
,Animation.RELATIVE_TO_PARENT,-0.02f);
mDotAnimation4.setDuration(500);
mDotAnimation4.setFillAfter(true);
}
这里是在这些动画之间切换的算法
public void aplicarMovimientoDot(double distanciaActual){
if(distanciaActual>=50){
//this.moverDot(-0.28f, -0.28f);
imgDot.startAnimation(mDotAnimation);
}
else if(distanciaActual<50 && distanciaActual >=25){
//this.moverDot(-0.21f, -0.21f);
imgDot.startAnimation(mDotAnimation1);
}
else if(distanciaActual<25 && distanciaActual >=10){
//this.moverDot(-0.13f, -0.13f);
imgDot.startAnimation(mDotAnimation2);
}
else if(distanciaActual<10 && distanciaActual >=2){
//this.moverDot(-0.08f, -0.08f);
imgDot.startAnimation(mDotAnimation3);
}
else if(distanciaActual<2){
//this.moverDot(-0.02f, -0.02f);
imgDot.startAnimation(mDotAnimation4);
}
}
最后布局XML,以防需要
<RelativeLayout
android:id="@+id/hackLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageView
android:id="@+id/imgArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="25dp"
android:src="@drawable/radar" />
<ImageView
android:id="@+id/imgDot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/dot" />
</RelativeLayout>
EDITED 好吧,在我冷静之后,我发现它始终从同一个地方开始的reazon是因为从初始化每个动画时采取维度。所以我的新问题将是..鉴于这个动画将被不断调用,如果我只保留一个动画的参考,每次我需要翻译它我使用新的翻译(所需的coorinates)? / p>