Las animaciones personalizadas para iniciar actividades en Android no funcionan como se esperaba
Soy algo nuevo para Android. Necesito personalizar animaciones en mi aplicación cuando se abren las actividades.
He utilizado el siguiente código en mi aplicación styles.xml
- Animación del tamaño de texto de TextView
- ¿Por qué mi animación no se repite?
- overridePendingTransition duración se ignora
- Android anima una lista de animación
- Nido de dos animaciones en Android
<style name="YourAnimation.Activity" parent="@android:style/Animation.Activity"> <item name="android:windowEnterAnimation">@anim/fade_in</item> <item name="android:windowExitAnimation">@anim/fade_out</item> </style>
A continuación, aplicó el estilo a un tema, en el mismo archivo.
<style name="YourTheme" parent="android:Theme.Translucent"> <item name="android:windowAnimationStyle">@style/CustomAnimationActivity</item> </style>
A continuación, agregó el tema en mi AndroidManifest.xml
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/YourTheme" > </application>
Pero, cuando estoy corriendo esto, se produce el siguiente error.
Creo que necesito agregar archivos de animación ml en algún lugar de mi proyecto. Pero, ninguna idea de cómo hacer eso. Alguien por favor me ayude con esto.
Gracias por adelantado. 🙂
-editar-
Aquí está el fade_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true"> <alpha android:duration="1000" android:fromAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="1.0"/> </set>
Aquí está el fade_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true"> <alpha android:duration="1000" android:fromAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="0.0"/> </set>
Registro de bloqueo
05-20 15:36:47.216 3557-3557/com.myayubo E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.myayubo, PID: 3557 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myayubo/com.myayubo.PreSplash}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5299) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:122) at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59) at com.myayubo.PreSplash.onCreate(PreSplash.java:23) at android.app.Activity.performCreate(Activity.java:5264) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5299) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) at dalvik.system.NativeStart.main(Native Method)
- Android imagen ver escala animación
- Animación de curl de página de actividad de Android
- Animación personalizada para el cajón de navegación
- Cómo animar la adición o la eliminación de Android ListView filas
- Cómo detener una animación (cancel () no funciona)
- Animación de Android dejando artefactos
- Cómo animar un elemento de la lista de capas
- Animar elementos recién agregados en ListView
En Android Studio:
- Haga clic derecho en la carpeta res.
- Nuevo> Directorio de recursos de Android.
- Para Tipo de recurso: seleccione anim.
- Presione Aceptar, y tiene la carpeta anim res.
A continuación, puede crear / incluir los elementos para su CustomAnimationActivity
como en sus styles
.
Editar después del registro del accidente
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.`
Simplemente cambie su styles.xml
para extender un tema de AppCompat
, por ejemplo
<style name="YourTheme" parent="android:Theme.AppCompat.Light"> <item name="android:windowAnimationStyle">@style/CustomAnimationActivity</item> </style>
Además, su Activity
probablemente debería extender AppCompatActivity
(o Activity
).
Intenta agregar archivos xml a continuación en la carpeta anim
Fadein.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="700" />
Fadeout.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator" android:zAdjustment="top" android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="700" />
Después de hacer esto simplemente añada el siguiente código en su actividad de salpicadura ( Nota: coloque este código después de terminar su intento)
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
- ¿Qué es packageContext en Intent # (Context packageContext, Class <?> Cls)?
- Objetivo de la cámara no funciona con Samsung Galaxy S3