要调用外部的xml布局,可以使用LayoutInflater来动态加载布局文件。具体步骤如下:
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.external_layout, null);
其中,R.layout.external_layout是你想要调用的外部xml布局的资源ID。
ViewGroup rootView = (ViewGroup) findViewById(R.id.root_layout);
rootView.addView(view);
其中,R.id.root_layout是当前布局中的一个容器,你可以根据你的实际情况来替换它。
通过上述步骤,你就可以成功调用外部的xml布局了。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:android getidentifier在xml布局中如何引用