admob smart_banner 在 java 代码中已弃用。但它在 XML 中未标记为已弃用。
我的 xml:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-xxx">
</com.google.android.gms.ads.AdView>
我的Java:
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
我的问题是,smart_banner 会起作用吗?我必须更改我的广告代码吗?难道我做错了什么? 谢谢 friend 。
最佳答案
Accordingly你没有做错任何事,智能横幅广告是有效的广告尺寸,但该网站说你应该使用 Adaptive Banner相应地更改横幅大小并且更受欢迎。
Adaptive banners are the next generation of responsive ads, maximizing performance by optimizing ad size for each device. Improving on smart banners, which only supported fixed heights, adaptive banners let developers specify the ad-width and use this to determine the optimal ad size.
您的 java 代码显示 AdSize.SMART_BANNER
已弃用,因为 docs对 use 说
public static AdSize getCurrentOrientationAnchoredAdaptiveBannerAdSize (Context context, int width)
而不是 AdSize.SMART_BANNER
,它返回具有给定宽度和 Google 优化高度的 AdSize 以创建横幅广告 |这在 xml 中不会发生,因为没有其他方法,您也应该使用以类似方式工作的自适应横幅广告。
如果您想使用它,您可以使用这种设置广告大小的方式
AdSize adSize = getAdSize();
adView.setAdSize(adSize);
并获取 adSize() 作为
private AdSize getAdSize() {
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
float widthPixels = outMetrics.widthPixels;
float density = outMetrics.density; int adWidth = (int) (widthPixels / density);
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(this, adWidth); }
关于java - 我还能在 XML 中使用 smart_banner 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67434312/