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,所以增加了一些東西給linearLayout
Field
是。 有什麼我做錯了(清楚)?
決定改變通脹方式。 View view = inflate(getContext(),R.layout.fragment_game_board_field,this); 現在佈局中出現了一些東西,但其形狀已經混亂了。 – justmatt