0

in my app I have a button and set below animation to it

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator" >

    <scale
        android:duration="2000"
        android:fromXScale="0.9"
        android:toXScale="1.0"
        android:fromYScale="0.9"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
       />

</set>

by this java code:

 myAnim = AnimationUtils.loadAnimation(this, R.anim.anim_button);
    Button myButton = (Button) findViewById(R.id.run_button);
    myButton.setAnimation(myAnim);
    myButton.startAnimation(myAnim);

now I want when button is focused (or pressed) the animation stopped and the size of my button reduced (for example from width 120dp to width 100dp) how can I do it? also I set below XML for my button

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_button_focuses"
        android:state_pressed="true"
        android:state_enabled="true"/>
    <item android:drawable="@drawable/ic_button_focuses"
        android:state_focused="true"
        android:state_enabled="true"/>
    <item android:drawable="@drawable/ic_button"
        />
</selector>
farshid83
  • 91
  • 1
  • 12

1 Answers1

0

in your java code to stop the animation

myButton.clearAnimation();
myButton.clearFocus();

to resize your button

myButton.setLayoutParams(new LinearLayout.LayoutParams(10, 100));

hope this may help you.!

Raju
  • 1,053
  • 2
  • 11
  • 17
  • tnx buddy, the animation that is set to my button is like a heart that beats. I want to stop beating when my finger touches the button (my finger is still on the button) – farshid83 Oct 07 '16 at 07:02
  • please refer here http://stackoverflow.com/questions/4112599/how-to-stop-an-animation-cancel-does-not-work – Raju Oct 07 '16 at 07:08
  • is there any listener method for focused button? – farshid83 Oct 07 '16 at 07:13
  • I found .isFocused() method for focusing button. myButton.isFocused() return true when button is focused but myButton.clearAnimation() is not worked!. – farshid83 Oct 07 '16 at 07:42