繁体   English   中英

Android-智能横幅-宽度不足(总是缺少一个像素)

[英]Android - Smart Banner - width not sufficient (always one pixel missing)

我想在我的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" /> 

它可以很好地与“ BANNER”一起使用,但如果始终为“ SMART_BANNER”,则总是小到一个像素,并显示以下错误:

W /广告:没有足够的空间来展示广告。 需要412x90 dp,但只有411x750 dp。 W /广告:没有足够的空间来展示广告。 需要412x90 dp,但只有411x750 dp。

问题:我在哪里丢了一个dp(从412降到411)?

添加信息:我正在使用模拟器(来自Android Studio)。 如果我使用“ Pixel 2XL API 26”(未显示SMART标语),则会出现使用问题,但是如果我使用“ Pixel API 28”,则正确显示标语

最好的问候安德烈亚斯

您需要将AdView的宽度设置为wrap_content而不是match_parent 至少这就是我对AdView所做的工作,无论它是BANNER还是SMART_BANNER,它始终可以正常工作。

[ android:layout_above="@+id/adView" ]我还注意到,在您的WebView上,您编写了android:layout_above="@+id/adView" 在这种情况下,您无需声明对adView的新引用,因为之前已经对其进行了声明。 因此,如果您只是使用@id/adView而不是@+id ,它将仍然有效。

另外,请尝试从布局和AdView中删除这些填充(即使将其设置为0)。 从我看来,他们是没有必要的。

您应该像这样设置宽度和高度:

  <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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM