4

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

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

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

帮助表示赞赏;)

4

1 回答 1

0

我的代码:明白...

点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);
        }
    });
于 2014-09-25T15:22:54.607 回答