I'm using animation between my fragment :
slide in from left :
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600"
android:propertyName="x"
android:valueFrom="2000"
android:valueTo="0"
android:valueType="floatType"
android:fillAfter="true"/>
</set>
slide in from right :
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="-400"
android:valueType="floatType"/>
</set>
This animation move the previous fragment to left and the new one come from the right. I'm using it with a fragment transaction.
transaction.setCustomAnimations(R.animator.slide_in_from_left,R.animator.slide_in_from_right);
I got a trouble when the new fragment come he slide below the older one, for fix it I put an elevation on my new fragment but I would like a solution for API below 21. Is it possible to force the new fragment to be above the older fragment
Fragments. A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment. The fragment’s view hierarchy becomes part of, or attaches to , ...
Fragments support AndroidX transitions . While fragments also support framework transitions, we strongly recommend using AndroidX transitions, as they are supported in API levels 14 and higher and contain bug fixes that are not present in older versions of framework transitions.
To animate the transition between fragments, or to animate the process of showing or hiding a fragment you use the Fragment Manager to create a Fragment Transaction. Within each Fragment Transaction you can specify in and out animations that will be used for show and hide respectively (or both when replace is used).
The Fragment API provides two ways to use motion effects and transformations to visually connect fragments during navigation. One of these is the Animation Framework, which uses both Animation and Animator. The other is the Transition Framework, which includes shared element transitions.
If I understand correctly, you are using the android:elevation
attribute on your new fragment (if not, feel free to write about your method) - altough it only works on Lollipop and above, as you also mentioned. However, based on the linked topic below there are several ways to achieve elevation effect on pre-Lollipop devices.
"android:elevation=" doesn't work on devices pre-Lollipop with compile API21
EDIT AFTER FIRST COMMENT: Okay, sorry for misunderstanding your question... :)
As I searched a little bit in the topic, there were some interesting examples with a new fragment overlapping an older one, they are listed below. The first 2 examples need some special layout design and extensions of existing view classes, but maybe one of them is what you're looking for.
FrameLayout
to replace fragments, it contains the fragment(s) by the <fragment>
tag; in the code you can use simple transition animations; you can find the source code at the end of the topic)RelativeLayout
view class with built-in functions to achieve animation; source code also provided at the end of the topic)Moreover (without source code) I could suggest you 2 more ways:
overridePendingTransition()
method inside the activity after startActivity(intent)
. However if
you really would like to use fragments, maybe you will skip this.I hope I could help... :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With