1

I need to create effect when fragment replace like side_in_left OR slide_out_right.

I used:

getSupportFragmentManager().beginTransaction().setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);

OR

Try this solution Link

but both are not working


This is code what I am using for replace fragment:

FragmentFirst dragabbleFragment = new FragmentFirst();
getSupportFragmentManager().beginTransaction().setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
getSupportFragmentManager().beginTransaction().replace(R.id.container, dragabbleFragment).commit();
Community
  • 1
  • 1
Akarsh M
  • 1,629
  • 2
  • 24
  • 47
  • Have you placed the animation XML in anim folder? If so, you need to use `R.anim not android.R.anim` – Skynet Mar 27 '14 at 05:44
  • I am using predefined value so, I used android.R.anim.*** and I also tried other but it also not working. As I mention Solution LINK ... @Nun'eChai – Akarsh M Mar 27 '14 at 05:59
  • For the other to work you need to put the relevant xml files in the Anim folder, I have used the same and it works fine. – Skynet Mar 27 '14 at 06:00
  • Could you please update that xml file and the code snippet. Beacuse I tried many solution from SO ... not working still @Nun'eChai – Akarsh M Mar 27 '14 at 06:02

1 Answers1

0
getSupportFragmentManager().beginTransaction().setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
getSupportFragmentManager().beginTransaction().replace(R.id.container, dragabbleFragment).commit();

I may be wrong but it could be because you're calling beginTransaction() twice and you're applying the animation to the first FragmentTransaction but calling replace(...) on the second.

Try...

FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
ft.replace(R.id.container, dragabbleFragment).commit();

EDIT: Try...

getSupportFragmentManager().beginTransaction().setCustomAnimations(...).replace(...).commit();

Obviously replace the ... parts with the bits you need - I left them out to keep the example short.

Squonk
  • 48,735
  • 19
  • 103
  • 135
  • replace give me error : The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, FragmentFirst) .. – Akarsh M Mar 27 '14 at 06:07
  • Does `FragmentFirst` extend `Fragment`? – Squonk Mar 27 '14 at 06:21
  • getSupportFragmentManager().beginTransaction().replace(R.id.container, dragabbleFragment).commit(); this is working fine – Akarsh M Mar 27 '14 at 06:22
  • i used this FragmentFirst dragabbleFragment = new FragmentFirst(); but i found this also from SO solution : CustomFragment newCustomFragment = CustomFragment.newInstance(); when I applied this newInstance() does not exist for me. – Akarsh M Mar 27 '14 at 06:24
  • You have to create your own `getInstance()` method in your `FragmentFirst` class if you want to use that way of doing things. As for the other issue, I don't understand why `getSupportFragmentManager.beginTransaction().replace(...).commit()` would work but not the way I suggested. Try chaining it all - see my edit above. – Squonk Mar 27 '14 at 06:31
  • I tried but not working .. May be I did something wrong .. I start with new demo and try to resolve this .. Thanks for the help :) – Akarsh M Mar 27 '14 at 06:50
  • @AM : OK, good luck. One other thing - as you are using the support libraries make sure all classes are from the android.support.v4 library. The standard `Fragment` and `FragmentTransaction` (for instance) aren't compatible with the support library classes. – Squonk Mar 27 '14 at 07:08