i have two linear layouts in one frame layout.
LayaoutParams usually create confusion while setting margin because of their parent layout... So this MarginLayoutParams is very useful which works with all layouts.
Java Code
MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams();
params.width = 200; //Ths value 200 is in px... Please convert in DP
params.leftMargin = 100;
params.topMargin = 200;
Kotlin code
val params: MarginLayoutParams = view!!.layoutParams as MarginLayoutParams
params.width = 200
params.leftMargin = 100
params.topMargin = 200