我有一个名为 myimage 的 ImageView。
我正在从一侧的屏幕外到另一侧的屏幕外进行 TranslateAnimation。
Animation animation = new TranslateAnimation(0, 0, -1500, 1500);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);
有什么方法可以让我将它从屏幕的一侧移到屏幕的另一侧,而不管屏幕尺寸如何?
最佳答案
我现在明白了。
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
final float screen_width_half = metrics.widthPixels/2;
final float distance = screen_width_half + 50;
//determine half screen width and add 50 to it to take it just a little outside the screen
Animation animation =
new TranslateAnimation(0, 0, -distance, distance);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);
关于android - 从一侧的屏幕外到另一侧的屏幕外进行 Translate TranslateAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28252379/