In my application, I have a layout which has a RelativeLayout to which I want to set margins at runtime programmatically. But when I do that, it gives me
I suggest that the parent of the @id/rl_root must be FrameLayout which is not showing in this xml. LayoutParam's type should be the same with its parent not itself.