Search code examples
javaandroidadmobads

What adSize for native express adview?


How can i set the adSize so that it matches the parent in width on all devices?

I tried setAdSize(AdSize.SMART_BANNER); but for some reason my ads don't show when i use this.

So for now i used mAdView.setAdSize(new AdSize(320,50); but not on all devices the width matches the full screen.

My code

        LinearLayout adContainer  = findViewById(R.id.adContainer);
        mAdView = new NativeExpressAdView(getApplicationContext());
        mAdView.setAdSize(new AdSize(320,50);
        mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
        adContainer.addView(mAdView);

        LinearLayout adContainer2  = findViewById(R.id.adContainer2);
        mAdView2 = new NativeExpressAdView(getApplicationContext());
        mAdView2.setAdSize(new AdSize(320,50);
        mAdView2.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
        adContainer2.addView(mAdView2);

        AdRequest adRequest = new AdRequest.Builder().addTestDevice("4EF772AE9549741BE0E1FCA236C7382C").build();
        mAdView.loadAd(adRequest);
        mAdView2.loadAd(adRequest);

EDIT

I tried mAdView.setAdSize(new AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT));

and it shows an ad with size 320*100, but there are black areas on the left and right side, so how can i set the adsize so that it matches the full screen?


Solution

  • Hi unfortunately we don't have that kind of customisation available for DFP ads. They come in fixed size only i.e. 320x50, 320x100, 320x250 you can't add padding to them can't stretch them. If you do they'll not appear.