我创建了一个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();
}
最佳答案
将此代码添加到onCreate
类中。确保将Systemerror
替换为返回的returnFrag
。
final AnimatorSet s1 = new AnimatorSet();
final ObjectAnimator anim = ObjectAnimator.ofFloat(returnFrag, "x", 150,0);
anim.setDuration(500);
s1.play(anim);
s1.start();
关于java - 将AnimatorSet添加到动态创建的FragmentTransaction中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25274851/