I have added 3 custom views (SmallTile.java) to another custom view (MyView.java; it is based on the deprecated AbsoluteLayout
- but I plan to change the base class later).
I am trying to position the 3 children by the following code in the parent:
@Override
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.d(APP, "w=" + w + "; h=" + h + ", oldw=" + oldw + ", oldh=" + oldh);
int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE)
return;
int x = mRandom.nextInt(w - child.getWidth());
int y = mRandom.nextInt(h - child.getHeight());
AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
x,
y
);
Log.d(APP, i + ": x=" + x + "; y=" + y);
}
requestLayout();
}
However eventhough I can see feasible positions in the debugger -
In the emulator all children are positioned wrong - at the origin:
What is going wrong here? I thought calling requestLayout()
would call AbsoluteLayout.onLayout() and thus redraw the children at the new random positions?
Here is a random picture from internet for a View lifecycle (I realize, that it isn't 100% true):