2016-08-03 75 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方法並決定手工膨脹佈局。

相關問題