【问题标题】:Translate animation to center screen将动画翻译为中心屏幕
【发布时间】:2013-02-18 06:40:54
【问题描述】:

我有一个RelativeLayout,里面有一个ImageViewImageView 在布局内随机定位。我正在尝试应用翻译动画,它将ImageView 从它的当前位置(x,y) 翻译到屏幕中心(x,y)

我已经尝试过类似下面的代码,但它没有解决问题。

<translate 
    android:fromXDelta="0%"
    android:toXDelta="50%"
    android:fromYDelta="0%"
    android:toYDelta="50%"
    android:duration="500"/>

帮助表示赞赏;)

【问题讨论】:

  • 您想从左、右、上、下翻译图像吗?是这样吗?
  • 是的,没错。从当前位置到中心(x 方向和 y 方向)
  • link同样的问题

标签: android android-animation


【解决方案1】:

我的代码: 明白...

Point windowSize = new Point();

    int totalWidth;


    //obtem o tamanho da tela que estamos trabalhando no momento
    if(Build.VERSION.SDK_INT > 12) {

        windowManager.getDefaultDisplay().getSize(windowSize);
        totalWidth = windowSize.x;
    }
    else
        totalWidth = windowManager.getDefaultDisplay().getWidth();

    //vamos animar ao centro
    final int totalWidthFinal = ((totalWidth / 2)  - (int)getDimension(R.dimen.fab_actions_spacing)) * -1;
    mFloatingActionButton.post(new Runnable() {

        @Override
        public void run() {

            int translationX =  totalWidthFinal;


            ViewPropertyAnimator.animate(mFloatingActionButton).setDuration(300).translationX(translationX);
        }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-01
    • 2016-05-22
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    相关资源
    最近更新 更多