AndroidStudio 3.6以后的视图绑定在fragment以及activity的用法不一问题注意下

在Activity中是

        inflate = ActivityLoginBinding.inflate(getLayoutInflater());
        setContentView(inflate.getRoot());

fragment:

        View view = inflater.inflate(R.layout.fragment_sub_main, container, false);
        mFragmentMainBinding= FragmentSubMainBinding.bind(view);
        return view;

这样理解,由于fragment的布局返回在oncreateview方法并且是个view对象,显然无法通过binding的inflate实现,所以通过bind绑定

猜你喜欢

转载自blog.csdn.net/kururunga/article/details/108441583