Last active
January 20, 2019 15:05
-
-
Save dynoChris/a06b47aeba4478da67754f1af22561eb to your computer and use it in GitHub Desktop.
How to set margin programmatically in Android?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void setMargins (View view, int left, int top, int right, int bottom) { | |
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { | |
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); | |
p.setMargins(left, top, right, bottom); | |
view.requestLayout(); | |
} | |
} | |
//How to call it — Utils.setMargin(imageView, 0, 20, 0, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment