且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使AdMob标语尺寸适合屏幕尺寸

更新时间:2021-10-24 05:50:29

将AdView添加到要显示横幅的布局文件中。
使用智能横幅尺寸属性。

Add AdView to your layout file in which you want to show banner. Use smart banner size attribute.

 <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/ad_id">

现在加载adView

Now load the adView

AdView mAdView;
    mAdView = (AdView) getActivity().findViewById(R.id.bac_adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice("xxxxxxxxxxxxxxxxxxxxxxxxxx") 
            .build(); 
    mAdView.loadAd(adRequest);

现在您的父布局为RelativeLayout,然后在adview中使用alignparentbottom属性属性来修复布局底部的添加。

Now your parent layout is RelativeLayout then use alignparentbottom attribute attribute in adview to fix the add at bottom of layout.

android:layout_alignParentBottom="true"

这看起来会更干净。