Попробуйте,
@SuppressLint("ClickableViewAccessibility")
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
anyView.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (v.getId()) {
case R.id.anyView:
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// perform here
}
break;
}
return false;
}
добавьте этот код в res / anim / rotate.xml
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1200"
android:interpolator="@android:anim/linear_interpolator"/>
Добавьте этот код в "// выполнить здесь" для поворота вида (Компонент)
imageView.startAnimation(AnimationUtils.loadAnimation(context,R.anim.rotate));
если вы используете android: repeatCount = "infinite", то вы динамически остановите вращение, примените этот код к определенному условию
imageView.clearAnimation();