Naveed
Naveed

Reputation: 11167

OnclickListener for Animated View

found many question on same issue.

How to set OnClickListener on the ImageView after rotation animation

How to write the onclick listener for a view after animation?

i also have same issue, any suggestion ?

Upvotes: 3

Views: 2363

Answers (1)

Trevor
Trevor

Reputation: 10993

You ought to write a fresh, concise question about your specific issue rather than just pointing to other questions. The two questions linked to aren't entirely clear.

I assume your issue is that after applying an animation (such as a TranslateAnimation, for example) to a View, the View no longer responds to touch events in its new position. The reason for this is because the View hasn't been moved to the new position in terms of layout parameters, but rather it has had a transformation applied.

The solution is quite simple: immediately after the animation has completed, actually move the View to the new position. You could set myAnimation.setFillAfter() = false, and set a listener to physically move the View to the target location when the animation has finished:

myAmazingAnimation.setFillAfter() = false;
myAmazingAnimation.setAnimationListener(new Animation.AnimationListener(){

                @Override
                public void onAnimationEnd(Animation animation) {
                          // Now actually move the View using LayoutParams
                }

                @Override
                public void onAnimationRepeat(Animation animation) {                    
                }

                @Override
                public void onAnimationStart(Animation animation) {
                }

            });

Another variation is to physically move the View at the beginning before animation is applied, and then apply an animation that makes the View start where it used to be and end at 0,0.

Upvotes: 3

Related Questions