How to move a view to another view using animation in Android?

后端 未结 2 1075
粉色の甜心
粉色の甜心 2021-01-14 09:14

I have a circle at the center of the screen inside which there\'s an ImageView + TextView. I have another two ImageView+TextView

2条回答
  •  清酒与你
    2021-01-14 09:50

    Using the getX() and getY() methods define the position of the view in pixels, but the constructor you use defines Float type values that must be values from 0.0f to 1.0f

    TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

    This is another option using the view`s position in pixels:

    viewFirst.animate()
            .x(viewSecond.getX())
            .y(viewSecond.getY())
            .setDuration(1000).withEndAction(new Runnable() {
        @Override
        public void run() {
            viewFirst.setX(tv2.getX());
            viewFirst.setY(tv2.getY());
        }
    }).start();
    

提交回复
热议问题