Ответ 1
Ну, я понял, где я ошибся. Я дал прописку моему изображению, которое заставило его немного отойти в сторону каждый раз, когда он вращался. В любом случае я удалил прокладку, и теперь она работает нормально.
Я пытаюсь сделать анимацию вращающегося изображения. Мне нужно повернуть значок вокруг , как и в панели прогресса, но то, что я получаю, - это изображение, вращающееся вокруг круга. Вот мой код анимации
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2500"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
Где я здесь ошибаюсь? Благодаря
Ну, я понял, где я ошибся. Я дал прописку моему изображению, которое заставило его немного отойти в сторону каждый раз, когда он вращался. В любом случае я удалил прокладку, и теперь она работает нормально.
Это исходный код макета main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/testButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="animationText"
android:onClick="AnimClick"/>
<ImageView
android:id="@+id/testImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="image_desc"
android:scaleType="fitCenter"
android:src="@drawable/cat2" />
</RelativeLayout>
Чтобы реализовать анимацию вращения, мы можем определить анимацию по XML или Java-коду. Если мы хотим записать анимацию в xml, нам нужно создать файл анимации xml в папке /res/anim. Здесь мы создаем xml файл с именем rotate_around_center_point.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="2500"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
и это моя деятельность:
public class MainActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.testButton);
btn.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
animationTarget.startAnimation(animation);
}
}
Вы можете попробовать со следующим кодом, а не делать это в XML:
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotate.setDuration(4000);
rotate.setRepeatCount(Animation.INFINITE);
yourView.setAnimation(rotate);
Добавьте в папку анимации следующий xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:duration="4000"
android:fromdegrees="0"
android:pivotx="50%"
android:pivoty="50%"
android:todegrees="360"
android:toyscale="0.0">
</set>
Надеюсь, это поможет вам.
для получения дополнительной информации http://www.blazin.in/2013/09/simple-rotate-animation-in-android.html