2016-08-03 70 views
0

我有layout.xml这是FrameLayout,它有另一个FrameLayout里面。
我有类Field子类FrameLayout包含逻辑,背景颜色等处理从FrameLayout充气布局并将其添加到LinearLayout

我想要做这样的事情:

Field f = new Field(width, height, color); //args can be changed if needed. 
linearLayout.addView(f); 

里面Field类的构造函数我这样做:

LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.game_board_field, null); 

因为它的子女数不是0,所以增加了一些东西给linearLayoutField是。 有什么我做错了(清楚)?

+0

决定改变通胀方式。 View view = inflate(getContext(),R.layout.fragment_game_board_field,this); 现在布局中出现了一些东西,但其形状已经混乱了。 – justmatt

回答

0

是的,就是这样。

View view = inflate(getContext(), R.layout.fragment_game_board_field, this); 

除此之外,我不得不纠正xml中的其他属性,因为我放弃了Frament方法并决定手工膨胀布局。

相关问题