D
D
Denis2017-05-24 23:06:32
Android
Denis, 2017-05-24 23:06:32

Why does view become non-clickable after animation?

Good day.
I have a task to swap view in LinearLayout with movement animation.
This is how I do it.

item_view = box_contact_profile.getChildAt(position);
Animation animationUp = AnimationUtils.loadAnimation(getActivity(), R.anim.swap_view_up);
animationUp.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
        Animation animationDown = AnimationUtils.loadAnimation(getActivity(), R.anim.swap_view_down);
        box_contact_profile.getChildAt(position - 1).startAnimation(animationDown);
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        View save_view = box_contact_profile.getChildAt(position);
        box_contact_profile.removeViewAt(position);
        v.setTag(position - 1);
        box_contact_profile.addView(save_view, position - 1);
        for (int i = position; i < box_contact_profile.getChildCount(); i++) {
            save_view = box_contact_profile.getChildAt(position);
            ImageButton but = (ImageButton) save_view.findViewById(R.id.but_menu_bloc_contact);
            but.setTag(i);
        }
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});
item_view.startAnimation(animationUp);

And here is the animation xml:
swap_view_down
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
>
<translate
    android:fromYDelta="0%"
    android:toYDelta="100%"
    android:duration = "200">

</translate>
</set>

swap_view_up
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
>
    <translate
        android:fromYDelta="0%"
        android:toYDelta="-100%"
        android:duration = "200"
        >

    </translate>
</set>

But after the animation, the block that I transferred (the one for which I called the presented code) stops responding to clicks. I suspect that its location does not match the display.
Perhaps the problem is similar to my other problem. I rotated the image and changed the image itself after the animation in the onAnimationEnd function, as a result, the image became rotated in the same direction as before the animation. In that case, I just started applying the new image before the animation.
Tell me what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2017-05-25
@lacredin

The problem is that the animation has parameters
android:fillBefore
android:fillAfter
If android:fillBefore = true, then all transformations with objects must be done before the animation starts, and if you do them at the end of the animation (in the onAnimationEnd listener), then the display of objects will return to its original state, but the objects themselves can change their location, as it was in my code.
And if android:fillAfter = true, then all transformations must be done after animation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question