I'm trying to do the following. Create a new Fragement B (Menu), slide it in from the right, and i want to move (no hide or replace!) the already shown Fragment A to the left.
I got the Transaction from Fragment B right, but Fragment A doesn't change his position at all. Seems like, my FragmentManager
doesn't know that Fragment A exists (Fragment A is not added dynamically, it's defined in XML).
main_screen_layout-xml
<RelativeLayout //... android:id="@+id/main_screen" tools:context=".MainActivity" <fragment android:id="@+id/map_screen" android:layout_width="fill_parent" android:layout_height="fill_parent" class="com.google.android.gms.maps.SupportMapFragment" > </fragment>
FragmentTransaction
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.add(R.id.main_screen, new MenuFragment(), MENU_FRAGMENT); //adding Fragment B ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left_cut); ft.addToBackStack(null); ft.commit();
Fragment A exists in the FragementManager
and I can hide it, but that's not my goal
Fragment fragmentA = fragmentManager.findFragmentById(R.id.map_screen);
ft.hide(fragmentA); //hide FragmentA
What am I doing wrong?
Some Notes:
- I'm using the Support Libaries (android.support.v4.app.FragmentManager..), but testing on API 17
- As mentioned before, I didn't declare FragmentA specifically to the
FragmentManager
(tried so, but it says Fragment already exists) - Fragment A is (as you can see in XML) a google map from class
SupportMapFragment
- The animation XML is working, that's why I didn't post it
I'm not sure if this is exactly what you are looking for, but check out this Sliding Menu library... it allows one to slide in a fragment from the left or right while shifting the center content fragment.
Solution:
Create Relative Layout with overlapping fragments:
and simply call
.translationX(-1 * mScreenWidth)
(mScreenWidth is my ScreenWidth minus the gap you want).