Imagen de Android rotación a través de archivo xml

He estado tratando de hacer un archivo de imagen girar sobre el terreno y estoy luchando, cada tutorial que encuentro parece hacer esto de una manera diferente.

¿Puede alguien señalar dónde me equivoco aquí.

GamePlay.java

import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.widget.ImageView; public class GamePlay extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gameplay); ImageView logo = (ImageView)findViewById(R.id.mainlogo); logo.setBackgroundResource(R.anim.rotate); AnimationDrawable frameAnimation = (AnimationDrawable) logo.getBackground(); frameAnimation.start(); } } 

Rotate.xml

 <?xml version="1.0" encoding="UTF-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="360" android:drawable="@drawable/logo" /> 

Gameplay.xml

 <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/mainlogo" android:src="@drawable/logo"> </ImageView> 

Cambiar rotate.xml a

 <?xml version="1.0" encoding="UTF-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1200" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:repeatCount="infinite" android:toDegrees="360" /> </set> 

Colóquelo en res / anim / carpeta

Y probar esto para iniciar la animación

 ImageView logo = (ImageView)findViewById(R.id.mainlogo); Animation rotateAnimation = AnimationUtils.loadAnimation(context, R.anim.rotate); logo.startAnimation(rotateAnimation); 

Pruebe este código; esto funciona para mi:

 ImageView img=(ImageView)findViewById(R.id.ImageView01); Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.snoopy); // Getting width & height of the given image. int w = bmp.getWidth(); int h = bmp.getHeight(); // Setting post rotate to 90 Matrix mtx = new Matrix(); mtx.postRotate(90); // Rotating Bitmap Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true); BitmapDrawable bmd = new BitmapDrawable(rotatedBMP); img.setImageDrawable(bmd); } 
  • Android Drawable: ¿Especificar el ancho de la forma en porcentaje en el archivo XML?
  • ¿Hay algo similar a los Drawables de Android en iOS?
  • Creación de un WebService ASP.net que devuelve JSON en lugar de XML
  • Android: se centra en EditText después de la selección de Spinner
  • Lollipop AppBarLayout / Barra de herramientas que falta la animación de overscroll
  • ¿Cuál es el punto de `Content_main.xml`?
  • OnItemClickListener de spinner
  • Volver a la actividad principal al presionar el botón del icono de la aplicación
  • No se puede resolver el símbolo 'R' en Android Studio: "la fusión manifiesta falló con varios errores, vea los registros"
  • Acolchado CardView y esquinas redondeadas
  • Error cómico en la declaración de forma xml de Android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.