一个Activity 对应 多个Fragment;
每一个类 extends Fragment ,
一个Activity 可以同时显示多个 Fragment;
Fragment是依赖于Activity的,而且生命周期也跟Activity绑定一起。
调用Activity:
Intent intent = new Intent(MainActivity.this, MainView.class); startActivity(intent);
Activity 调用xml 文件:
public class MainView extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.wificonfig,container,false); } }
调用Fragment:
getSupportFragmentManager().beginTransaction().replace(R.id.drawer_layout, new Robotview()).commit();
Fragment 调用 xml layout:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_robotview, container, false); }