5

.setCustomAnimations(R.animator.in_animation, R.animator.out_animation) the following throws "Expected respource type of anim"

getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations(R.animator.in_animation, R.animator.out_animation)
            .replace(R.id.a_fragment, SingleAnswerFragment.newInstance())
            .addToBackStack(null)
            .commit();

I did check this stack over flow thread Android Studio's "expected resource of type" checks? and I did see where in this case I might use @Animator Res annotation, but i'm not sure how I would use that in the middle of my method chaining as shown above

https://stackoverflow.com/a/18511350/5596604 Here I see a possible solution but have no idea what he means in his steps where he, (Imported the NineOldAndroids library into the support-v4 Library Imported the support-v4-nineoldandroids library into my project.) The github link for that support library for NineOldAndroids, states in the configuration part " remove Google's support v4 library from your classpath."

Community
  • 1
  • 1
MrBoutte'
  • 349
  • 4
  • 14

3 Answers3

7

You are providing R.animator resources (@AnimatorRes) to the setCustomAnimations() method but it expects R.anim resource type (@AnimRes). If you switch to some animations which are referenced by R.anim it should compile and work.

but i'm not sure how I would use that in the middle of my method chaining as shown above

I'm not sure what you mean by this. Maybe this could shed some light on the matter. Also here you can find a list of all the Android annotations with short descriptions.

JKMirko
  • 161
  • 5
  • sorry I meant in this line .setCustomAnimations(R.animator.in_animation, R.animator.out_animation) how would I use the @Animatorres to suppress the warning – MrBoutte' Mar 08 '16 at 22:16
  • You should use [this](http://developer.android.com/reference/android/R.anim.html) resources. E.g. `.setCustomAnimations(R.anim.fade_in, R.anim.fade_out)`. You wouldn't use the `@AnimatorRes` annotation to suppress the warning, the warning is there because you are using `R.animator` and not `R.anim`. – JKMirko Mar 08 '16 at 22:20
  • I switched my animations to a anim folder and now the app crashes when I click for animation, I'm getting this error, java.lang.RuntimeException: Unknown animation name: objectAnimator – MrBoutte' Mar 08 '16 at 22:34
  • You'll have to provide more information than that. Please edit your question and provide more code samples and the exception stacktrace. – JKMirko Mar 08 '16 at 22:41
1

You can use setCustomAnimations with Property Animation only with android.app.Fragment. And with android.support.v4.app.Fragment you should use TweenAnimation.

Leonid
  • 4,953
  • 2
  • 10
  • 13
0

I'm pretty sure that you are using fragment of class android.support.v4.app.Fragment, but not android.app.Fragment. This class is not allowing property animation that you try to use. If so, change your fragment to android.app.Fragment (change all other accordingly, for example getSupportFragmentManager() to getFragmentManager()), this should help.

Borg8
  • 1,562
  • 11
  • 19