[英]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.