您的位置:首页 > 其它

fragment 动态添加,以及防止穿透

2016-07-19 16:03 447 查看
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();//防止穿透
@Overridepublic 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() {@Overridepublic 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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: