将AnimatorSet添加到动态创建的FragmentTransaction中

时间:2014-08-12 22:04:59

标签: java android android-animation fragmenttransaction

我创建了AnimatorSet s1

我想使用s1 AnimatorSet代替R.anim.slide_in_top

如何告诉transaction使用s1

private void showsystemerror(int i){
    dialog.cancel();
    Systemerror frag = new Systemerror();
    Bundle bundle = new Bundle();
    bundle.putInt("type", i);
    frag.setArguments(bundle);
    final AnimatorSet s1 = new AnimatorSet();
    final ObjectAnimator anim = ObjectAnimator.ofInt(frag, "x", 150,0);
    anim.setDuration(500);
    s1.play(anim);

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.anim.slide_in_top, 0);
    transaction.add(R.id.main, frag);
    transaction.commit();
}

1 个答案:

答案 0 :(得分:1)

onCreate中的此代码添加到您的Systemerror课程中。请务必将returnFrag替换为variable

    final AnimatorSet s1 = new AnimatorSet();
    final ObjectAnimator anim = ObjectAnimator.ofFloat(returnFrag, "x", 150,0);
    anim.setDuration(500);
    s1.play(anim);
    s1.start();