LayoutInflater,在RelativeLayout中打开活动的打开布局

时间:2012-04-13 16:24:27

标签: android xml android-intent layout-inflater

我有一个“Tools.java”,显示“tools.xml”是否正确?在这个“tools.xml”中,RelativeLayout的布局id = @ + / contentLayout是空的。

我还有其他几个活动“tool1.java”,“tools2.java”...显示“tool1.xml”,“tool2.xml”......

如何调用类“tool1.java”,让它在“tools.xml”中的RelativeLayout中显示“tool1.xml”

由于

1 个答案:

答案 0 :(得分:0)

看看这个

// this is you relativelayout from tool.xml
    RelativeLayout relativeLayout = (RelativeLayout )findViewById(R.id.contentLayout);

    LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);



                  // tool1 is your tool1.xml
            View tool1 = inflater.inflate(R.layout.tool1, null,false);

                // here add tool1 to tool.xml in relativelayout
            relativeLayout.addView(tool1 );