Android如何调用外部xml布局
要调用外部的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布局了。
TOP