gpt4 book ai didi

android - 从一侧的屏幕外到另一侧的屏幕外进行 Translate TranslateAnimation

转载 作者:太空宇宙 更新时间:2023-11-03 13:20:45 25 4
gpt4 key购买 nike

我有一个名为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com