Android buttonimage shake animation Android buttonimage shake animation xml xml

Android buttonimage shake animation


Replace your shakeanim.xml file with this.

<set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:duration="150"        android:fromXDelta="-10%"        android:repeatCount="5"        android:repeatMode="reverse"        android:toXDelta="10%"/></set>

btw you can change your MainActivity "setOnClickListener" like this as you have already declared imageButton.

imageButton.setOnClickListener(new OnClickListener() {            @Override             public void onClick(View v) {                clicks--;                               clicksToGo.setText("You need to click " + clicks + " more times to open it");                imageButton.startAnimation(shake);              }          }); 

If this helps please mark it as the right answer. Thank you