确切的尺寸是“没有足够的空间”。满足需求使用Admob的dp [英] Exact dimensions of "not enough space" given for needs & has dp using Admob

查看:124
本文介绍了确切的尺寸是“没有足够的空间”。满足需求使用Admob的dp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试设置左侧&



在Nexus5X上,我看到测试广告:





更新:我看到这则奇怪的错误消息:



ar W / Ads:没有足够的空间来展示广告。需要411x49 dp,但只有411x49 dp。



???

解决方案

在xml文件中,将您的根布局从Linear Layout更改为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_centerHorizo​​ntal = 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>


I tried setting the left & right padding margins to 0 per 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>

On a Nexus5X, I see "Test Ad":

Update: I am seeing this bizarre error message:

ar W/Ads: Not enough space to show ad. Needs 411x49 dp, but only has 411x49 dp.

???

解决方案

In xml file, Change your root layout to RelativeLayout from Linear Layout and also remove "android:layout_weight="512" from first child LinearLayout.

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

这篇关于确切的尺寸是“没有足够的空间”。满足需求使用Admob的dp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆