[英]Android - Smart Banner - width not sufficient (always one pixel missing)
I want to add a SMART_BANNER at the bottom of my Android App (HTML5), the layout is defined as follows 我想在我的Android应用(HTML5)的底部添加一个SMART_BANNER,布局定义如下
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="0dp" android:paddingRight="0dp" android:background="@color/default_header" > <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto" android:id="@+id/adView" android:background="@color/add_background" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="0dp" android:paddingRight="0dp" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" ads:adSize="SMART_BANNER" ads:adUnitId="@string/ad_banner"> </com.google.android.gms.ads.AdView> <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/adView" android:background="@color/start_background" android:id="@+id/webView" />
It works perfectly fine with "BANNER" but in case of a "SMART_BANNER" always with is always one pixel to small and the following error is shown: 它可以很好地与“ BANNER”一起使用,但如果始终为“ SMART_BANNER”,则总是小到一个像素,并显示以下错误:
W/Ads: Not enough space to show ad. W /广告:没有足够的空间来展示广告。 Needs 412x90 dp, but only has 411x750 dp.
需要412x90 dp,但只有411x750 dp。 W/Ads: Not enough space to show ad.
W /广告:没有足够的空间来展示广告。 Needs 412x90 dp, but only has 411x750 dp.
需要412x90 dp,但只有411x750 dp。
Question: Where did I lose the one dp (from 412 to 411)? 问题:我在哪里丢了一个dp(从412降到411)?
Add info: I am using an emulator (from Android Studio). 添加信息:我正在使用模拟器(来自Android Studio)。 Using issue occurs if I use a 'Pixel 2XL API 26' (SMART banner not shown), but the banner is correctly shown if I use a 'Pixel API 28'
如果我使用“ Pixel 2XL API 26”(未显示SMART标语),则会出现使用问题,但是如果我使用“ Pixel API 28”,则正确显示标语
Best regards Andreas 最好的问候安德烈亚斯
You need to set the AdView's width to wrap_content
instead of match_parent
. 您需要将AdView的宽度设置为
wrap_content
而不是match_parent
。 At least that's what I do with my AdViews and it always works regardless if it's a BANNER or SMART_BANNER. 至少这就是我对AdView所做的工作,无论它是BANNER还是SMART_BANNER,它始终可以正常工作。
[Off-topic] I've also noticed that on your WebView you wrote android:layout_above="@+id/adView"
. [
android:layout_above="@+id/adView"
]我还注意到,在您的WebView上,您编写了android:layout_above="@+id/adView"
。 In this case you don't need to declare a new reference to adView since it's already been declared before. 在这种情况下,您无需声明对adView的新引用,因为之前已经对其进行了声明。 So if you simply put
@id/adView
instead of @+id
it will still work. 因此,如果您只是使用
@id/adView
而不是@+id
,它将仍然有效。
Also try removing those paddings (even though it's set to 0) both from your layout and the AdView. 另外,请尝试从布局和AdView中删除这些填充(即使将其设置为0)。 There is no need for them from what I see.
从我看来,他们是没有必要的。
you should set width and height like this : 您应该像这样设置宽度和高度:
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_unitid_web">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.