【问题标题】:Getting the absolute location of an image after a translate Animation翻译动画后获取图像的绝对位置
【发布时间】:2015-08-10 00:17:34
【问题描述】:

我有一张图片。单击按钮时,图像上会发生翻译动画,因此它会向左滑动,您最终只能看到一定比例的图像。

有没有办法在翻译动画发生后获取图像的位置?我意识到我可以使用动画侦听器并在 OnAnimationEnd 方法中执行某些操作。但是,我不确定在这里做什么......

如何获取图像移动到的位置并将其设置为图像的布局参数?

我真的可以在这里使用您的帮助。

【问题讨论】:

    标签: android android-animation


    【解决方案1】:

    假设您当前的图像位置是 x, y。你在 x 方向 100,y 方向 50 移动。所以你当前的位置是 newx =x+100,newy=y+50。您将在 onAnimationEnd 方法中使用您的布局放置图像。

     TranslateAnimation TAnimation=new TranslateAnimation(0, 100, 0, 50)        
        TAnimation.setDuration(2000);
        TAnimation.setFillAfter(true);
        Image.startAnimation(TAnimation);
     TAnimation.setAnimationListener(new AnimationListener() {
    
            public void onAnimationStart(Animation animation) {
    
            }
    
            public void onAnimationRepeat(Animation animation) {
    
            }
    
            public void onAnimationEnd(Animation animation) {
    
                RelativeLayout RL=(RelativeLayout)findViewById(R.id.rl);
                    param=new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
                param.setMargins(x+100, y+50, 0, 0);
                    Image.setLayoutParams(param);
    
            }
        });
    

    【讨论】:

      【解决方案2】:

      我知道这个问题很老,但它可能会对某人有所帮助。 您可以添加:

      animation.setFillAfter(true);
      

      或在 Xml 集中:

       fillAfter = "true"
      

      就是这样。它将强制视图处于新位置

      【讨论】:

        猜你喜欢
        • 2016-02-04
        • 2012-01-31
        • 1970-01-01
        • 2014-03-23
        • 2014-06-29
        • 1970-01-01
        • 1970-01-01
        • 2016-01-27
        • 1970-01-01
        相关资源
        最近更新 更多