Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android button not clickable while playing animations

I have a button and while this button is playing an animation, I'm not able to click on button. I've set click listener and touch listener but in debug mode it's not entering in OnClick and in onTouch methods. Do you know why? Thanks

edit: I've tried something like:

        AsyncTask task = new AsyncTask() {

        @Override
        protected Object doInBackground(Object... objects) {
            button1.setOnClickListener(new View.OnClickListener() {

                public void onClick(View view) {
                    Toast toast = Toast.makeText(MyActivity.this, button1.getText(), Toast.LENGTH_SHORT);
                    toast.show();
                }
            });
            return null;
        }

        ;
    };
    task.execute(button1);

but it's not working

Edit: here is the full source code

like image 948
Buda Gavril Avatar asked Oct 13 '11 19:10

Buda Gavril


2 Answers

Before Android 3.0, using any of the animation classes only changes where the view is drawn - it won't adjust its touchable-bounds during (or after) the animation: http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html

You could:

  • Make a ViewGroup which moves its children every onDraw
  • Override your View's onDraw to move itself - Could use margin or padding, or position (if view is in a FrameLayout or something similar).
  • Only use 3.0+ devices
  • Override the parent's onTouch (or onInterceptTouchEvent), calculate where the View is being drawn (you can get how far into and the offset from real position from the Animation *) and handle accordingly... * Looking at your code (since you generate a random direction each time it finishes), this might not be possible without tracking which directions you've previously take..
like image 67
FunkTheMonk Avatar answered Sep 18 '22 00:09

FunkTheMonk


you are facing same issue that i was recently ... when you apply animation on button or any other view and use setFillAfter(True) it means that the image of view is moved not the actual view thats why its not listening to your click listener because its just image of view not your actual view you have to do something like that i explained in answer to my own question according to your situation... means you have to also move the actual view on the end place of animation and use setFillAfter(false) so that when you click after anmation then it should be an actual view not just image used for animation purpose by android

check this link....

EditText stucks after animation and alive back on scrolling......?

In your code use setFillafter(false) and actually place your button at end position of animation by somehow like setting margin or according to your layout use appropriate properties for placement. By Applying these changes your click listener will work perfectly.

==> if you are trying that your button's click listener work while its moving (being animate) then as far as i know its not possible because android uses just image of your view to perform animation not the actual.

like image 34
Umar Qureshi Avatar answered Sep 19 '22 00:09

Umar Qureshi