Made the button animation spin around its axis in the setOnTouchListener method. And how to make such an animation, so that when you press the button, it shakes? In one program I saw this. I would like to do this in my own way. In this program, the number buttons shake https://play.google.com/store/apps/details?id=com.gokids.bphone1

rotate.xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" > <rotate android:duration="2000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:startOffset="0" android:toDegrees="360" /> </set> 

MainActivity

 public class MainActivity extends AppCompatActivity { ImageButton imageButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); imageButton = (ImageButton) findViewById(R.id.imageButton); final Animation animationRotateCenter = AnimationUtils.loadAnimation(this, R.anim.rotate_center); imageButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { view.startAnimation(animationRotateCenter); return false; } }); } } 
  • Nobody knows how to make such an animation? - Christina

1 answer 1

Try it, in 1 example we shift the object by 10 pixels, and in 2 we repeat the same offset 5 times:

1 (Anim.xml)

 <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="0" android:interpolator="@anim/cycle5" android:toXDelta="10" /> 

2 (Cycle5.xml)

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="5" />

Ps you can try to make an offset to the top and down and then loop)