Android 参数说明

1.inflater.inflate(R.layout.crime_fragment, container, false);

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.crime_fragment, container, false);
        return  mView;
    }

第一个是布局ID。第二个参数是视图的父视图,我们通常需要父视图来正确配置 组件。第三个参数告诉布局生成器是否将生成的视图添加给父视图

 

 

 

 mTranstaction.add(R.id.frament_container,mFragment);

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crime);
        FragmentManager mFm = getSupportFragmentManager();
        Fragment mFragment = mFm.findFragmentById(R.id.frament_container);
        if (mFragment == null) {
            mFragment = new CrimeFragment();
            FragmentTransaction mTranstaction = mFm.beginTransaction();
            mTranstaction.add(R.id.frament_container,mFragment);
            mTranstaction.commit();

        }
    }
add(),第一个参数为容器ID,第二个为内容Fragment
posted @ 2018-05-30 10:43  XinYiBuFang  阅读(417)  评论(0编辑  收藏  举报