在xml中创建时,需要params layout_width和layout_height.
在Java代码中创建的项目怎么样?它们的默认布局是什么?
如何以编程方式将其布局设置为fill_parent或wrap_content?
Ale*_*dam 13
public void addView(View child)从:API Level 1
添加子视图.如果尚未在子项上设置布局参数,则会在子项上设置此ViewGroup的默认参数.参数child要添加的子视图另请参见
generateDefaultLayoutParams()
Run Code Online (Sandbox Code Playgroud)
如果没有其他参数,则addView(View)使用默认参数(主要是WRAP_CONTENT).看一下源代码,
protected LayoutParams [More ...] generateDefaultLayoutParams() {
if (mOrientation == HORIZONTAL) {
return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
} else if (mOrientation == VERTICAL) {
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4501 次 |
| 最近记录: |