0
我遇到以下問題:我在我的android應用程序中有一個動畫,它在屏幕上移動了UI元素,即它是一個翻譯動畫,它通常工作正常。讓我們說,它正在從位置(0,0)移動到(0,200)在屏幕上。問題是,有時這種情況發生得非常快(如0.001秒),一旦程序加載,我就看不到物體的移動,但是我發現它處於最終位置(0,200)。這裏是我的代碼:Android動畫快速結束
Handler handler = new Handler();
float height;
private RelativeLayout relativeLayoutDoughnutAndLogoTogether;
private RelativeLayout logo_donut_together2;
private ImageView imgSplash, image2;
private DoughnutView doughnutView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relativeLayoutDoughnutAndLogoTogether = (RelativeLayout) findViewById(R.id.logo_donut_together);
logo_donut_together2 = (RelativeLayout) findViewById(R.id.logo_donut_together2);
imgSplash = (ImageView) findViewById(R.id.turkcell_logo);
image2 = (ImageView) findViewById(R.id.ImageView02);
int logoHeight = imgSplash.getDrawable().getIntrinsicHeight();
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
final int centerScreen = (screenHeight-logoHeight)/2;
doughnutView = new DoughnutView(this) {
@Override
public void onAnimationComplete() {
float density = getResources().getDisplayMetrics().density;
Animation moveToTop = new TranslateAnimation(0, 0, centerScreen-50*density, 0);
moveToTop.setDuration(1000);
relativeLayoutDoughnutAndLogoTogether.startAnimation(moveToTop);
logo_donut_together2.setVisibility(View.GONE);
logo_donut_together2.removeView(doughnutView);
relativeLayoutDoughnutAndLogoTogether.addView(doughnutView);
relativeLayoutDoughnutAndLogoTogether.setVisibility(0);
}
};
doughnutView.setStartAngle(0);
doughnutView.setColorFront(Color.rgb(232, 232, 232));
doughnutView.setSweepAngle(360);
doughnutView.setStrokeWidth(4);
doughnutView.setMarginAll(10);
doughnutView.setColorBack(Color.rgb(63, 176, 232));
doughnutView.startAnimation(0);
logo_donut_together2.addView(doughnutView);
}
我實際上是在談論onAnimationComplete部分的代碼。如果有人能幫忙,我將不勝感激。
感謝