Using this package com.google.android.gms.ads.AdSize; I can set my adsize like this
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
But this gms.ads is old one. Is there any alternative way in which we can achieve the same thing in the new package ie, com.google.ads.AdSize; Thanks in Advance
You can set custom ads size by this way,
AdSize customAdSize = new AdSize(250, 250);
PublisherAdView adView = new PublisherAdView(this);
adView.setAdSizes(customAdSize);
you can set multiple AdSize parameters into setAdSizes()
adView = new AdView(this);
// adView.setAdSizes(AdSize.BANNER);
adView.setAdSizes(AdSize.BANNER, new AdSize(120, 20), new AdSize(250, 250));
you can check AdSize() Documentation
Hope this help you!
you can easily set a custom size like this in XML.
ads:adSize="400x400"
You can create a custom Ad dynamically as following
View adContainer = view.findViewById(R.id.adMobView);
AdSize customAdSize = new AdSize(150, 150);
AdView mAdView = new AdView(context);
mAdView.setAdSize(customAdSize);
mAdView.setAdUnitId(context.getResources().getString(R.string.banner_ad_unit_id));
((RelativeLayout)adContainer).addView(mAdView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
in your xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:background="#000"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/adMobView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
For Changing adsize you can change these lines in new Google Ads..
change this line accordingly..
adView.setAdSize(AdSize.BANNER);
You can see the details here..
https://developers.google.com/mobile-ads-sdk/docs/admob/intermediate
Banner Sizes
Google Mobile Ads supports the following ad formats:
Size (WxH) Description Availability AdSize Constant 320x50 Standard Banner Phones and Tablets BANNER 300x250 IAB Medium Rectangle Tablets MEDIUM_RECTANGLE 468x60 IAB Full-Size Banner Tablets FULL_BANNER 728x90 IAB Leaderboard Tablets LEADERBOARD See table Smart Banner Phones and Tablets SMART_BANNER
Hope you find the solution here..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With