0

Сделала анимацию кнопки вращение вокруг своей оси в методе setOnTouchListener. А как сделать такую анимацию, чтобы при нажатии на кнопку она тряслась? В одной программе увидела такое. Хотела бы и в своей так сделать. В этой программе кнопки с цифрами так трясутся 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;
            }
        });
    }
}
1
  • Никто не знает как сделать такую анимацию? 20 апр 2017 в 12:48

1 ответ 1

0

Попробуй , в 1 примере сдвигаем объект на 10 пикселей , а во 2 повторяем подобное смещение 5 раз:

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" />

P.s можно попробовать сделать смещение в верх и вниз и потом зациклить)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.