Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created February 11, 2016 10:11
Show Gist options
  • Save arturaz/aa2964b7518614822426 to your computer and use it in GitHub Desktop.
Save arturaz/aa2964b7518614822426 to your computer and use it in GitHub Desktop.
void addToUI(int width, int height, boolean isTopBanner) {
float density = activity.getResources().getDisplayMetrics().density;
int finalWidth = (int)(width * density);
int finalHeight = (int)(height * density);
bannerFrame = new FrameLayout(activity);
RelativeLayout.LayoutParams bannerLayoutParams =
new RelativeLayout.LayoutParams(finalWidth, finalHeight);
bannerFrame.addView(banner, bannerLayoutParams);
ViewGroup root = (ViewGroup) activity.getWindow().getDecorView();
root.addView(bannerFrame, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT,
(isTopBanner ? Gravity.TOP : Gravity.BOTTOM) | Gravity.CENTER_HORIZONTAL
));
Log.d(TAG, "Banner added to UI.");
setVisibilityUI(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment