Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

Android FragmentTransaction Custom Animation (Unknown Animator Name: Translate)

I'm trying to get a custom animation to work with my fragment.

I've followed the online tutorials but I've been getting the below error:

java.lang.RuntimeException: Unknown animator name: translate

The XML for the animation is below:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
    android:fromXDelta="100%"
    android:toXDelta="0"
    android:duration="300" />
</set>

The Java file is shown below:

public void goCategory(View v) {        
    FragmentTransaction ft = fm.beginTransaction();     
    ft.setCustomAnimations(R.animator.anim_in_left, R.animator.anim_out_left);              
    ft.show(fragment);
    ft.commit();
}

I'm having trouble understanding the solutions in the other threads. If someone could dumb it down for me, I'd really appreciate it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Probably you are mixing two apis. There are two cases:

  • If targeting below 3.0 or using support v4 fragments: You have to use the old animations api, that is, the one you are using (they go into anim/, and are R.anim.thing)

  • If you are targeting above 3.0 and using native fragments: You have to use the new animation apis, that is, ObjectAnimators (they go into animator/ and are R.animator.thing).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...