Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created February 11, 2016 10:37
Show Gist options
  • Save arturaz/7f555be24b39fe1b83f7 to your computer and use it in GitHub Desktop.
Save arturaz/7f555be24b39fe1b83f7 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);
bannerFrame.addView(banner, new FrameLayout.LayoutParams(
finalWidth, finalHeight,
(isTopBanner ? Gravity.TOP : Gravity.BOTTOM) | Gravity.CENTER_HORIZONTAL
));
ViewGroup root = (ViewGroup) activity.getWindow().getDecorView();
root.addView(bannerFrame, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
));
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