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

标签 android image animation screen-size

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

相关文章:

java - Dagger 2 - 构造函数注入(inject) - 作用域

Android studio Firebase 依赖与 appcompat 不兼容

java - `Leaderboard` 选项卡未显示在 Google Play 游戏中,而 `Achievements` 选项卡存在

android - Admob 中介 + Millenial Media 插页式广告。如何?

python - 如何使用负值保存 PIL 图像

javascript - 点点点点点点作为加载?

python - 如何使用 python 从图像中提取元数据?

HTML + CSS - 使用超链接居中图像

iphone - 用动画替换静态 UIImageView

python - 为什么悬停动画会忽略 Gtk3 中的过渡时间和功能?