【问题标题】:Add AnimatorSet to a FragmentTransaction created dynamically将 AnimatorSet 添加到动态创建的 FragmentTransaction
【发布时间】:2014-08-12 22:04:58
【问题描述】:

我创建了一个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();
}

【问题讨论】:

    标签: java android android-animation fragmenttransaction


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-03
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多