我有两个布局文件:main.xml 和 buttonpanel.xml。在 buttonpanel.xml 中,我将其中的 main linearlayout 的 gravity 设置为 bottom。现在我正在尝试使用以下代码添加 buttonpanel 布局。
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中,则可以正常工作。能否有人帮我看看我的代码哪里出了问题?