一、简介最近做项目涉及到了很多关于Fragment跳转的问题,虽然跳转的方式不多,但还是搞的我的晕头转向,所以写了一篇文章主要介绍有关Fragment的四种跳转方式:1、从同一个Activiy的一个Fragment跳转到另外一个Fragment
2、从一个Activity的Fragment跳转到另外一个Activity
3、从一个Activity跳转到另外一个Activity的Fragment上
4、从一个Activity的Fragment跳转到另外一个Activity的Fragment上
二、准备工作(两个Activity和三个Fragment)1、布局
在MainActivity的布局文件中写一个子布局
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>2、创建两个java类文件继承v4包的Fragment,并重写onCreateView方法引用对应的Fragment布局文件(这里以其中一个为例)public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (contentView == null) {
contentView = inflater.inflate(R.layout.my_fragment, container, false);
最后
以上就是阳光奇迹最近收集整理的关于android跳转方法,Android Fragment 四种跳转方法的全部内容,更多相关android跳转方法,Android内容请搜索靠谱客的其他文章。
发表评论 取消回复