It appears that the old view animations (translate
, scale
, and so on) are no longer accepted by the AnimationInflater
, at least as of ICS. I read its code in 4.0.4, and it explicitly expects only the XML elements set
, objectAnimator
, animator
.
Even though the documentation at http://developer.android.com/guide/topics/resources/animation-resource.html continues to include the view animations, they appear to be deprecated. Trying to use them results in, for instance, the error java.lang.RuntimeException: Unknown animator name: translate
.
As such, it becomes necessary to use Android's ObjectAnimator
. However, it does not accept fractional values of the associated dimension of itself or its parent (width for translationX
, for example) as the old view animations did in the form "75%p"
.
Constructing the ObjectAnimator
manually at runtime, by programmatically fetching the size of the Fragment, isn't feasible because the FragmentTransaction
only accepts declarative animations specified by a resid.
My goal is to translate offscreen a Fragment that is filling up an entire Activity (I'm basically doing a shift transition between two fragments). This is the existing TranslationAnimation
implementation (slide_in_right.xml
, which along with its counterpart slide_out_left.xml
is for some reason not exposed in android.R.anim
, and I therefore have to duplicate them in my codebase):
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
My API level is set to 14.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…