【发布时间】:2010-10-08 09:59:30
【问题描述】:
http://code.google.com/android/reference/android/widget/AbsoluteLayout.html 的文档说:
onLayout(boolean changed, int l, int t, int r, int b)
//Called from layout when this view should assign a size and position to each of its children.
所以我这样覆盖它:
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
Log.d("test", "In MainLayout.onLayout");
int childCount = getChildCount();
for (int childIndex = 0; childIndex < childCount; childIndex++) {
getChildAt(childIndex).setLayoutParams(new LayoutParams(100, 100, 100, 100));
}
super.onLayout(changed, l, t, r, b);
}
我在 XML 中为布局声明子元素(按钮)。
这会正确设置按钮的位置,但不能正确设置大小。大小取自 XML 中定义的内容(这是必需的属性)。
【问题讨论】: