FragmentTransaction ft = getChildFragmentManager().beginTransaction();
SpeciesDialogFragment dialogFragment = new SpeciesDialogFragment();
Bundle bundle = new Bundle();
bundle.putString("familyID",familyID);
bundle.putString("familyName",familyName);
dialogFragment.setArguments(bundle);
ft.replace(R.id.fragment_replace,dialogFragment);
// ft.setCustomAnimations(width,heigh,R.style.animal_dialog_anim);
ft.commit();
getChildFragmentManager().executePendingTransactions();//防止穿透
添加的时候是楼上说的,回退的时候调用@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mRootView == null) { mRootView = inflater.inflate(R.layout.fragment_species_dialog, container, false); } mRootView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) {return true;//防止穿透 } });
getSupportFragmentManager().popBackStack();//suport.v4包
或getFragmentManager().popBackStack();
自定义转场动画
自定义转场动画是通过setCustomAnimations()方法,因为Fragment添加时可以指定加入到Back Stack中,所以转场动画有添加、移除、从Back stack中pop出来,还有进入四种情况。
注意setCustomAnimations()方法必须在add、remove、replace调用之前被设置,否则不起作用。
fragmentTransaction.setCustomAnimations(
R.animator.fragment_slide_left_enter,
R.animator.fragment_slide_right_exit);