In my application, when a user presses a button in the menu, I would like the button to scale to a larger size, and then when the button is released, it needs to scale back to its original size. In xml, I have created the following animator:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together">
<objectAnimator
android:propertyName="scaleX"
android:duration="100"
android:valueFrom="1.0"
android:valueTo="1.3"
android:valueType="floatType"/>
<objectAnimator
android:propertyName="scaleY"
android:duration="100"
android:valueFrom="1.0"
android:valueTo="1.3"
android:valueType="floatType"/>
</set>
On the Android developer page, it says you can create a state list for a custom button, like so:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused"
android:state_focused="true" />
<item android:drawable="@drawable/button_default" />
</selector>
I have the custom background, so my question is: is there any way to apply my animation to the drawable in a state list like this? Or would I have to apply the animation to each button in my Java code? My application has a lot of buttons, so setting the animation for each one individually in Java would get very long. If I do have to apply the animation in the Java code, the button's onclick method is only called when the button is released, how would I detect when the button is first pressed down?