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);
相关文章推荐
- 阶梯博弈算法详解(尼姆博弈进阶)
- 京东一元抢宝系统的数据库架构优化
- Proximal Algorithms--Fixed points
- BZOJ 3289 Mato的文件管理
- 对 Android 开发者有益的 40 条优化建议
- iOS性能的优化
- 手机端输入框过滤表情JS代码
- ES6的编码风格
- Android应用QQ第三方登录出现100044提示
- org.springframework.beans.factory.BeanCreationException
- angular.element的常用方法
- Java快速排序的具体实现
- JS的冒泡函数
- 嵌入式学习-linux系统-lesson3-文件系统的制作及nfs挂载
- Full gc的触发条件
- IOS 静态库生成
- IOS 静态库生成
- oracle行转列
- 程序3-3 蛇形填数
- android实现登录发送短信验证码或者语音验证码以及一个倒计时的内部类