Анимированная позиция переключения двух кнопок

Я пытаюсь поменять положение двух кнопок. Мой код обмена выглядит так:

private void exchangeButtons(Button btn1, Button btn2) {
    // Create the animation set
    AnimationSet exchangeAnimation = new AnimationSet(true);
    TranslateAnimation translate = new TranslateAnimation(
        Animation.RELATIVE_TO_SELF, btn2.getLeft(),
        Animation.RELATIVE_TO_SELF, btn1.getLeft(),
        Animation.RELATIVE_TO_SELF, btn2.getRight(),
        Animation.RELATIVE_TO_SELF, btn1.getRight());
    translate.setDuration(500);
    exchangeAnimation.addAnimation(translate);
    //int fromX = btn1.getLeft();
    //int fromY = btn1.getRight();
    //int toX = btn2.getLeft();
    //int toY = btn2.getRight();
    Log.d("ArrangeMe", 
        "view1 pos:" + btn1.getLeft() + ", 
        " +btn1.getRight() + "view2 pos:" + 
        btn2.getLeft() + ", " + btn2.getRight());
    AnimationSet exchangeAnimation1 = new AnimationSet(true);
    TranslateAnimation translate1 = new TranslateAnimation( 
        Animation.RELATIVE_TO_SELF, btn1.getLeft(),
        Animation.RELATIVE_TO_SELF, btn2.getLeft(),
        Animation.RELATIVE_TO_SELF, btn1.getRight(),
        Animation.RELATIVE_TO_SELF, btn2.getRight());
    translate1.setDuration(500);
    exchangeAnimation1.addAnimation(translate1);
    // EXECUTE btn1.startAnimation(exchangeAnimation);
    btn2.startAnimation(exchangeAnimation1);
}

Я называю код, как показано ниже:

exchangeButtons(button1, button2);

Мой макет выглядит так:



    
    
    
    

Что произойдет, когда я выполню код:

Вместо того, чтобы кнопки поменялись местами, они просто исчезают на некоторое время [может быть, через 500 мс) и снова появляются, как они были изначально.

Как решить эту проблему? Будет ли это работать должным образом в устройстве?

Ответы на вопрос(2)

Ваш ответ на вопрос