当前位置: 代码迷 >> Android >> 怎么动态载入布局
  详细解决方案

怎么动态载入布局

热度:65   发布时间:2016-05-01 21:07:06.0
如何动态载入布局?

我在setcontent了一个布局文件,里面有个RelativeLayout的ID为ToboundContent。
现在想把另一个ID为Content的布局文件塞进ToboundContent里。

这个应该很简单的吧。求解答。希望回答的清楚点,我是小白。

------解决方案--------------------
mView = (RelativeLayout) findViewById(R.id.ToboundContent);
mView.addView(view);
view另一个布局文件。
------解决方案--------------------
LayoutInflater mInflater = LayoutInflater.from(context);
view = mInflater.inflate(R.layout.global_menu_layout, null);
------解决方案--------------------
综合楼上的做法,就可以实现了。
LayoutInflater mInflater = LayoutInflater.from(context);
view = mInflater.inflate(R.layout.global_menu_layout, null);
先把你的view实例化,然后调用ViewGroup的addView(),就可以了。
  相关解决方案