[英]Setting ad width to match_parent
所以我的應用程序中有廣告,我不想將它們的寬度設置為match_parent
。 如果將其設置為match_parent
則仍顯示為wrap_content
,並且如果將其設置在java文件中,例如adView.setAdSize(AdSize.SMART_BANNER);
我收到此消息Caused by: java.lang.IllegalStateException: The ad size can only be set once on AdView
崩潰: Caused by: java.lang.IllegalStateException: The ad size can only be set once on AdView
這是我的廣告的xml和java:
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
<com.google.android.gms.ads.AdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/adView"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
如果我將其設置為SMART_BANNER,即使我從xml代碼中刪除了ads:adSize="BANNER"
行,也遇到了上面提到的錯誤。
請嘗試這個
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
ads:adUnitId="@string/banner_ad_unit_id"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub_id"
ads:loadAdOnCreate="true"/>
但是請記住,如果廣告客戶提供的所有正確資源都超過,則只有您的廣告在match_patent的寬度內可見
您可以使用FULL_WIDTH
ads:adSize="FULL_WIDTHx50"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.