2

In an android application I am implementing an Animation on an ImageButton. After the animation the button remains at it's last frame but it is only clickable at it's initial position, I have Implemented an BounceInterpolation animation by these line of code in my main .java Activity

TranslateAnimation translation;
translation = new TranslateAnimation(0f, 0F, 0f, 200);
translation.setStartOffset(150);
translation.setDuration(100);
translation.setFillAfter(true);
translation.setInterpolator(new BounceInterpolator());
mTourButton.startAnimation(translation);

I don't know how to update the the ImageButton parameters. Most of the solutions are for the xml implemented animations. I didn't find any solution. I am tired now please help.

Mauker
  • 11,237
  • 7
  • 58
  • 76
Dushyant Suthar
  • 673
  • 2
  • 9
  • 27
  • 1
    Take a look at this: http://stackoverflow.com/questions/9067778/button-is-not-clickable-after-translateanimation – daemmie Aug 02 '15 at 11:05
  • 1
    I have tried all the 3-4 solutions listed since I asked the question but people I just want to update the parameters to the last frame of animation. I think setLayoutParams() method can be helpful but I don't even know what should i pass as arguments. – Dushyant Suthar Aug 02 '15 at 11:44

2 Answers2

0

Try to use onTouch() to handle your clicks.

imageButton.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch(event.getAction())
        {
            case MotionEvent.ACTION_UP :
            {
            // Do whatever you want here.
            }
        return true;
    }
});

That should do it.

Mauker
  • 11,237
  • 7
  • 58
  • 76
0

Better add onClick in XML:

 <ImageButton
    android:onClick="doSomethingMethod"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton"
    android:layout_above="@+id/imageView"
    android:layout_centerHorizontal="true" />

Press ALT+ENTER on doSomethingMethod and Create 'doSomethingMethod(View)' in 'Activity'

This will create a method like onClickListener in your Activity.

Hope it helps!

Chris
  • 6,105
  • 6
  • 38
  • 55