2
我想爲在屏幕中心開始的ImageView創建動畫,並將其向上移動10px以下到屏幕頂部。我如何在代碼中實現這一點?Android - 從中間到頂部的翻譯動畫
我現在正在做的是,我將屏幕座標放在另一張圖像上,並將此動畫圖像置於其上,但在高密度大屏幕中,它不保留相同的距離,所以我想把它從頂部移動10px。
我該如何做到這一點?
這裏是我的代碼:
//calculate where to put the logo in y-axis depending on screen size
int coords[] = {0,0};
logoImageFixed.getLocationOnScreen(coords);
int y = coords[1];
int imgFixedHeight = logoImageFixed.getHeight();
Log.d("daim","height: "+imgFixedHeight);
float pointY = -(y + 3*imgFixedHeight);
Animation a = new LogoAnimation(0.0f, 0.0f, 0.0f, pointY);
a.setFillAfter(true);
a.setDuration(600);
a.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
logoAnimated = true;
}
});
logoImage.startAnimation(a);