Monday, 12 January 2015

Set Margin on scal Metrics of devices dynamically.

Simple code snippet to Set Margin on scal Metrics of devices dynamically.

MarginLayoutParams marginParams = new MarginLayoutParams(
frameLayout.getLayoutParams());
final float scale = getResources().getDisplayMetrics().density;
leftMargin = (int) (leftMargin * scale );
marginParams.setMargins(leftMargintopMargin, 0, 0);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
marginParams);
layoutParams.gravity = Gravity.NO_GRAVITY// This is the new line
frameLayout.setLayoutParams(layoutParams);

Happy Codding

No comments:

Post a Comment