I have a custom view derived from Button , which I want to position at runtime, relative to another view. Since I do not yet know that the other position of the view when my view is inflated (since the layout has not started yet), I use the onSizeChanged handler to set the position of my view relative to another view.
In onSizeChanged :
LayoutParams lp = new LayoutParams(this.getMeasuredWidth(), this.getMeasuredHeight()); lp.leftMargin = x; lp.topMargin = y; this.setLayoutParams(lp); forceLayout();
This, however, has no effect. Why?
source share