我为 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/