2013-09-25 25 views
17

ja dostaję ten błąd przy użyciujava.lang.RuntimeException: Nieznana nazwa animacja: objectAnimator

getActivity().getSupportFragmentManager() 
         .beginTransaction() 
         .setCustomAnimations(
           R.animator.card_flip_right_in, R.animator.card_flip_right_out, 
           R.animator.card_flip_left_in, R.animator.card_flip_left_out) 
         .replace(R.id.content_fragment, new DaysSinceBirthSettingFragment()) 
         .addToBackStack(null) 
         .commit(); 

Ale kiedy go zmienić na

getActivity().getFragmentManager() 
         .beginTransaction() 
         .setCustomAnimations(
           R.animator.card_flip_right_in, R.animator.card_flip_right_out, 
           R.animator.card_flip_left_in, R.animator.card_flip_left_out) 
         .replace(R.id.content_fragment, new DaysSinceBirthSettingFragment()) 
         .addToBackStack(null) 
         .commit(); 

Działa idealnie. ale muszę obsługiwać starszą wersję, więc muszę użyć support-v4, z którego pochodzi getSupportFragmentManager().

czytałem jakiś artykuł mówiący, że res/animator nie jest wspierany przez pomoc-V4, więc próbowałem również przenieść moje animowanych plików XML do res/anim folderu i odniesienie go R.anim.card_flip_right_in

Ale nadal to nie działa, ktoś może mi powiedzieć, co mogę zrobić?

Odpowiedz

21

Menedżer fragmentów pomocy nie obsługuje animatorów (tylko animacje). Komunikat o wyjątkach mówi, że masz błędny format animacji w twoim źródle xml, prawdopodobnie dlatego, że przeniesiono animatora do tego xml, który jest nieprawidłowy (ponieważ mają inną notację). Musisz napisać go w odpowiedni sposób: http://developer.android.com/guide/topics/graphics/view-animation.html

+0

nie używam fragmentów wsparcia, nadal wyjątek występuje! –

4

jeśli używasz fragmentu support dodać poniżej plików xml w OZE

zostanie poniższe treść Anim/fragment_slide_left_enter.xml plików.

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromXDelta="100%p" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toXDelta="0%p" /> 

    <alpha 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromAlpha="0.0" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toAlpha="1.0" /> 
</set> 

następujący będzie treść anim/fragment_slide_left_exit.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromXDelta="0%p" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toXDelta="-100%p" /> 

    <alpha 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromAlpha="1.0" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toAlpha="0.0" /> 
</set> 

następujący kod będzie treść Anim/fragment_slide_right_enter.xml plików

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromXDelta="-100%p" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toXDelta="0%p" /> 

    <alpha 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromAlpha="0.0" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toAlpha="1.0" /> 
</set> 

następujący kod będzie zawartość anim/fragme nt_slide_right_exit.xml plik

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 

    <translate 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromXDelta="0%p" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toXDelta="100%p" /> 

    <alpha 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromAlpha="1.0" 
     android:interpolator="@android:interpolator/decelerate_quint" 
     android:toAlpha="0.0" /> 
</set> 

wreszcie dodać tę linię w kodzie fragmentu przejściowego

ft.setCustomAnimations(R.anim.fragment_slide_left_enter, 
         R.anim.fragment_slide_left_exit, 
         R.anim.fragment_slide_right_enter, 
         R.anim.fragment_slide_right_exit) 
Powiązane problemy