制作机器人动画翻译按屏幕宽度 [英] Making android Translate animations as per screen width

查看:261
本文介绍了制作机器人动画翻译按屏幕宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这篇code为Android的翻译X轴动画 -

I wrote this code for an android Translate Animation on x axis -

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个单位中的所有屏幕尺寸。

This image moves the same 80 units on all screen sizes.

有没有什么办法,使其移动等于屏幕宽度的80%?

Is there any way so that it moves a distance equal to 80% of the screen width ?

推荐答案

您可以只是自己进行计算:

You can just calculate it yourself:

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);

这篇关于制作机器人动画翻译按屏幕宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆