Hit*_*dra 10 android android-layout
我有两个布局:main.xml和buttonpanel.xml.在buttonpanel.xml中,在main linearlayout中,我将gravity设置为bottom.现在我尝试使用以下代码添加按钮面板布局.
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,它可以正常工作.
任何人都可以帮我解决我的代码有什么问题吗?
Arl*_*ren 17
在以您正在进行的方式膨胀视图时,我遇到了布局参数被丢弃的问题.如果我使用稍微不同的调用inflate我的布局参数是受到尊重的:
parent_view = inflater.inflate(R.layout.buttonpanel, parent);
或者在我的情况下,当父母不支持向其添加视图时:
view = inflater.inflate(R.layout.buttonpanel, parent, false);
也许这也将解决您的问题.
编辑:根据给定的参数返回不同的视图.LayoutInflater
| 归档时间: | 
 | 
| 查看次数: | 15778 次 | 
| 最近记录: |