Местоположение GifImageView в onAnimationEnd не изменилось. - PullRequest
0 голосов
/ 26 мая 2020

У меня есть RelativeLayout, который запускает анимацию в новую позицию, и я изменяю его layoutMargins в onAnimationEnd () после очистки анимации. В большинстве случаев код работает отлично, но иногда RelativeLayout возвращается в исходное положение после завершения анимации и не переходит go в новую позицию, если я не изменю какое-либо изображение из любого GifImageView в макете. Почему так происходит? и почему изменение любого изображения в GifImageView в макете влияет только на RelativeLayout?

ПРИМЕЧАНИЕ. RelativeLayout не содержит GifImageView, в котором изображение должно быть изменено. Макет создается динамически, но RelativeLayout содержит GifImageView + TextView. Когда я попытался изменить изображение в GifImageView в RelativeLayout, это не помогло.

Я использую pl.droidsonroids.gif.GifImageView

    MoveAnim.setAnimationListener(new TranslateAnimation.AnimationListener() {

        boolean AnimationEnded = false;
        @Override
        public void onAnimationStart(Animation animation) {
            AnimationEnded = false;

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (!AnimationEnded) {


                findViewById(R.id.relativelayout).clearAnimation();

                //The Calculations of the margins are correct
                ((RelativeLayout.LayoutParams)findViewById(R.id.relativelayout).getLayoutParams()).setMargins((int) ((snowCharacter.getPosition()%10 -1.25) * BlockWidth),(int)((snowCharacter.getPosition()/10 -1.45) * BlockHeight),0,0);

                //This Line fix the bug that need any image to be changed to refresh the Relative Position
                ((GifImageView) findViewById(R.id.any_gif).setImageResource(R.drawable.card72));

                //Reverse the image of the GifImageView to not affect the Design
                ((GifImageView) findViewById(R.id.any_gif).setImageResource(R.drawable.last_image));


                AnimationEnded = true;
            }
        }
    });
...