I have a custom view, derived from Button
, which I want to position at runtime, relative to another view. Because I don't know that other view's position yet when my view is being inflated (because layouting hasn't started), I leverage the onSizeChanged
handler to set my view's position relative to the other view.
In onSizeChanged
:
LayoutParams lp = new LayoutParams(this.getMeasuredWidth(), this.getMeasuredHeight());
lp.leftMargin = x;
lp.topMargin = y;
this.setLayoutParams(lp);
forceLayout();
That, however, has no effect. How come?