【问题标题】:Doing Translate TranslateAnimation from just outside the screen on one side to just outside the screen on the other side将 TranslateAnimation 从一侧的屏幕外翻译到另一侧的屏幕外
【发布时间】:2023-03-31 13:10:02
【问题描述】:

我有一个名为 myimage 的 ImageView。

我正在TranslateAnimation从一侧的屏幕外到另一侧的屏幕外。

Animation animation = new TranslateAnimation(0, 0, -1500, 1500);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);

有什么方法可以让我将它从一侧的屏幕外移动到另一侧的屏幕外,而不管屏幕尺寸如何?

【问题讨论】:

    标签: android image animation screen-size


    【解决方案1】:

    我已经拿到了。

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

    【讨论】:

      猜你喜欢
      • 2012-01-07
      • 2014-09-11
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      相关资源
      最近更新 更多