Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set adSize?

Tags:

android

admob

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

like image 213
sunil sunny Avatar asked Apr 04 '14 04:04

sunil sunny


4 Answers

You can set custom ads size by this way,

Custom Size

AdSize customAdSize = new AdSize(250, 250);
PublisherAdView adView = new PublisherAdView(this);
adView.setAdSizes(customAdSize);

you can set multiple AdSize parameters into setAdSizes()

Multiple ads sizes

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!

like image 191
Jaykumar Patel Avatar answered Sep 24 '22 16:09

Jaykumar Patel


you can easily set a custom size like this in XML.

ads:adSize="400x400"
like image 37
zia Shahid Avatar answered Sep 24 '22 16:09

zia Shahid


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"
   />

like image 24
Amrutha Saj Avatar answered Sep 24 '22 16:09

Amrutha Saj


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..

like image 26
PankajSharma Avatar answered Sep 21 '22 16:09

PankajSharma