我有兩個佈局:main.xml和buttonpanel.xml。在buttonpanel.xml中,在主線性佈局中,我將重力設置爲底部。現在我試圖使用下面的代碼添加buttonpanel佈局。如何使用layoutinflator在運行時添加視圖?
setContentView(R.layout.main);
LinearLayout layout=(LinearLayout)findViewById(R.id.mainlinearlayout);
LayoutInflater inflater= (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.buttonpanel,null);
layout.addView(view);
我的問題是面板被添加到頂部,但我已經在buttonpanel.xml中將重力設置爲底部。如果我使用include將buttonpanel.xml添加到main.xml,它工作正常。
任何人都可以幫助我什麼是我的代碼有問題嗎?
[使LayoutInflater有意義](http://stackoverflow.com/questions/5026926/making-sense-of-layoutinflater) – 2012-07-03 12:49:25
請檢查以獲得更詳細的解釋:http://stackoverflow.com/questions/5026926/making-sense-of-layoutinflater – andig 2011-02-17 09:16:46