Android Studio Setmargin

TextView txt = (TextView) findViewById(R.id.txt);
MarginLayoutParams marginParams = (MarginLayoutParams) txt.getLayoutParams();
marginParams.setMargins(left, top, right, bottom);
adreaskar