android - 根据屏幕宽度制作android Translate动画

标签 android image animation

我为 x 轴上的 android 翻译动画编写了这段代码 -

ImageView myimage = (ImageView)findViewById(R.id.myimage);

Animation animation = new TranslateAnimation(0, 80, 0, 0);
animation.setDuration(100);
animation.setFillAfter(true);
myimage.startAnimation(animation);

此图像在所有屏幕尺寸上移动相同的 80 个单位。

有什么办法让它移动的距离等于屏幕宽度的80%?

最佳答案

你可以自己计算一下:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float calculatedWidth = metrics.widthPixels * 0.8f;

Animation animation = new TranslateAnimation(0, calculatedWidth, 0, 0);
animation.setDuration(100);
animation.setFillAfter(true);

关于android - 根据屏幕宽度制作android Translate动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28073335/

相关文章:

c++ - OpenCV 使用像素指针构建图像

android - 如何在 android 中为不同的 2 密度(如 mdpi、ldpi、hdpi)使用 9 个补丁图像。?

android - 如何动画化 ListView 的扩展?

android - 使用 interpolatedTime == 1 调用两次 applyTransformation

Android 如何在 Android 2.3 及更高版本的 MediaPlayer 中播放 Shoutcast AAC、AAC+、MP3?

android - 查看android上google plus的 Activity 列表

ios - 来自 images.xcassets 的 Xcode 5 切片图像,在 xib 中正确拉伸(stretch),但在运行时不正确

ios - QuartzCore 动画形状?

java - 如何在 Android 中禁用以前的 Activity

android - 带有嵌入式浏览器的 Google OAuth 2.0 和强制门户