How do Admob banner fill full width?

Asked

Viewed 328 times

3

Hello zeroes padding of XML and put wrap_content, but the banner of AdMob does not fill all width is spaces as solve?

Code:

<?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="match_parent"
    android:layout_height="match_parent"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context="br.com.planetsweb.dolarhoje.Tela1"
    android:background="#e8e8e8">


    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_alignParentBottom="true">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

1 answer

2


The width of AdView varies depending on attribute adSize. You can check these sizes in Announcements of banner.

On the other hand, instead of using AdView you can replace with InterstitialAd. The Interstitial ads are full screen ads that cover the application interface. Typically, they are displayed at natural transition points in the flow of an app, such as between activities or during a pause between levels in a game. When an app displays an interstitial, the user can choose to tap the ad and move to the landing page or close it and return to the app.

Here’s how to add interstitial ads to a Activity:

public class MainActivity extends ActionBarActivity {

    InterstitialAd mInterstitialAd;
    Button mNewGameButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mNewGameButton = (Button) findViewById(R.id.newgame_button);

        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
                beginPlayingGame();
            }
        });

        requestNewInterstitial();

        mNewGameButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                } else {
                    beginPlayingGame();
                }
            }
        });

        beginPlayingGame();
    }

    private void requestNewInterstitial() {
        AdRequest adRequest = new AdRequest.Builder()
                  .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
                  .build();

        mInterstitialAd.loadAd(adRequest);
    }

    private void beginPlayingGame() {
        // Play for a while, then display the New Game Button
    }
}

Take an example:

inserir a descrição da imagem aqui

See details in the documentation.

  • Its link was useful the size SMART_BANNER that completes all width, already use the interstitial ad.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.