首页 > 代码库 > Android常用工具类封装---Fragment
Android常用工具类封装---Fragment
Fragment切换
/** ** Fragment切换 @Params toFragment 将要切换到的Fragment resId 装载Fragment的view Id index Fragment的标识index toleft 判断Fragment向左切换还是向右切换,以采用不同的动画 Notes: R.anim.push_left_in等均为简单的Tranlate动画 mCurrentFragment为当前所在的Fragment,继承自BaseFragment */ protected void switchDiffFragmentContent (Fragment toFragment, int resId, int index, boolean toleft){ if (null == mCurrentFragment || null == toFragment){ return; } if (mCurrentFragment.getArguments().getInt("Index") != toFragment.getArguments.getInt("index")) { FragmentTransaction fragmentTransaction; fragmentTrasaction = getChildFragmentManager().beginTransaction(); if (toleft) { fragmentTrasaction.SetCustomAnimations(R.anim.push_left_in, R.anim.push_left_out); }else{ fragmentTrasaction.setCustomAnimations(R.anim.push_right_in, R.anim.push_right_out); } //先判断是否添加过 if (!toFragment.isAdded()) { //隐藏当前fragment,add下一个fragment fragmentTrasaction.hide(mCurrentFragment); fragmentTrasaction.add(resId, toFragment, String.valueOf(index)); fragmentTransactoin,commit(); }else{ //隐藏当前fragment,show下一个fragment fragmentTransaction.hide(mCurrentFragment); fragmentTransaction.show(toFragment); fragmentTransaction.commit(); } mCurrentFragment = (BaseFragment)toFragment; } }
Android常用工具类封装---Fragment
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。