根据需要给出 "not enough space" 的确切尺寸,并使用 Admob 获得 dp
Exact dimensions of "not enough space" given for needs & has dp using Admob
我尝试将左右填充边距设置为 0 Not enough space to show ad (AdMob)
Error: W/Ads: Not enough space to show ad. Needs 411x49 dp, but only has 411x49 dp.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, String.valueOf(R.string.ad_app_id));
mAdView = findViewById(R.id.adView);
AdRequest.Builder b = new AdRequest.Builder();
b.addTestDevice((AdRequest.DEVICE_ID_EMULATOR));
b.addTestDevice("<Redacted>");
AdRequest adRequest = b.build();
mAdView.loadAd(adRequest);
initialiseView();
}
private void initialiseView() {
LinearLayout mLinearLayout = findViewById(R.id.linearLayout);
mGameView = new GameView(this);
mLinearLayout.addView(mGameView, 0);
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp"
>
<LinearLayout
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_weight="512"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linearLayout">
</LinearLayout>
<RelativeLayout
android:layout_weight="1"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<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"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-XXX">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</LinearLayout>
在 Nexus5X 上,我看到 "Test Ad":
更新:我看到这条奇怪的错误消息:
ar W/Ads: space 不足以显示广告。需要 411x49 dp,但只有 411x49 dp。
???
在 xml 文件中,将根布局从线性布局更改为 RelativeLayout,并从第一个子 LinearLayout 中删除 "android:layout_weight="512"。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<RelativeLayout
android:id="@+id/rvAd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<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"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-XXX"></com.google.android.gms.ads.AdView>
</RelativeLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/rvAd"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp">
</LinearLayout>
</RelativeLayout>
我尝试将左右填充边距设置为 0 Not enough space to show ad (AdMob)
Error: W/Ads: Not enough space to show ad. Needs 411x49 dp, but only has 411x49 dp.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, String.valueOf(R.string.ad_app_id));
mAdView = findViewById(R.id.adView);
AdRequest.Builder b = new AdRequest.Builder();
b.addTestDevice((AdRequest.DEVICE_ID_EMULATOR));
b.addTestDevice("<Redacted>");
AdRequest adRequest = b.build();
mAdView.loadAd(adRequest);
initialiseView();
}
private void initialiseView() {
LinearLayout mLinearLayout = findViewById(R.id.linearLayout);
mGameView = new GameView(this);
mLinearLayout.addView(mGameView, 0);
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp"
>
<LinearLayout
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_weight="512"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linearLayout">
</LinearLayout>
<RelativeLayout
android:layout_weight="1"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<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"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-XXX">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</LinearLayout>
在 Nexus5X 上,我看到 "Test Ad":
更新:我看到这条奇怪的错误消息:
ar W/Ads: space 不足以显示广告。需要 411x49 dp,但只有 411x49 dp。
???
在 xml 文件中,将根布局从线性布局更改为 RelativeLayout,并从第一个子 LinearLayout 中删除 "android:layout_weight="512"。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<RelativeLayout
android:id="@+id/rvAd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<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"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-XXX"></com.google.android.gms.ads.AdView>
</RelativeLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/rvAd"
android:orientation="vertical"
android:paddingLeft="0dp"
android:paddingRight="0dp">
</LinearLayout>
</RelativeLayout>