没有足够的空间来展示广告。需要360x50 dp,但只有360x0 dp

时间:2018-05-26 04:52:15

标签: android android-layout admob

第二次打开它时,我的应用程序崩溃了。我是否收到错误“没有足够的空间显示广告。需要360x50 dp,但只有360x0 dp。”。以下是用于显示广告的布局。我的第一个活动不使用广告。当我退出第一个活动,并再次打开应用程序工作正常。我的第二个活动也有adview,也有退出选项。当我退出第二个活动(下面给出布局),然后再次打开应用程序时,它会崩溃。因为只有当我退出第二个活动时才会出现问题。我怀疑adview是在崩溃的背后,但我不确定。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.sunplus.suniq.activity.FresherActivity"
    tools:showIn="@layout/activity_fresher">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ListView
            android:id="@+id/simpleListView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="@color/material_blue_grey_800"
            android:dividerHeight="1dp"
            android:footerDividersEnabled="false" />

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            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="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

这就是logcat显示的内容。(不知何故原始错误在logcat中发生了变化,但在执行问题上是相同的)。关闭应用程序,然后再次打开它会崩溃。

W/ResourceType: No package identifier when getting value for resource number 0x00000258
W/ImageView: Unable to find resource: 600
             android.content.res.Resources$NotFoundException: Resource ID #0x258
                 at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:224)
                 at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
                 at android.content.res.Resources.getDrawable(Resources.java:819)
                 at android.content.Context.getDrawable(Context.java:605)
                 at android.widget.ImageView.resolveUri(ImageView.java:915)
                 at android.widget.ImageView.setImageResource(ImageView.java:477)
                 at com.android.volley.toolbox.ImageLoader$1.onResponse(ImageLoader.java:112)
                 at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:229)
                 at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:191)
                 at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:182)
                 at com.sunplus.suniq.adapter.CustomAdapter.getView(CustomAdapter.java:80)
                 at android.widget.AbsListView.obtainView(AbsListView.java:2365)
                 at android.widget.ListView.measureHeightOfChildren(ListView.java:1408)
                 at android.widget.ListView.onMeasure(ListView.java:1315)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                 at android.view.View.measure(View.java:22071)
                 at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1028)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
                 at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
                 at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
                 at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:809)
                 at android.view.View.measure(View.java:22071)
                 at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1059)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                 at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                 at com.android.internal.policy.DecorView.onMeasure(DecorView.java:724)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2422)
                 at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1504)
                 at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761)
                 at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
                 at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                 at android.view.Choreographer.doCallbacks(Choreographer.java:723)
                 at android.view.Choreographer.doFrame(Choreographer.java:658)
                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                 at android.os.Handler.handleCallback(Handler.java:790)
                 at android.os.Handler.dispatchMessage(Handler.java:99)
                 at android.os.Looper.loop(Looper.java:164)
                 at android.app.ActivityThread.main(ActivityThread.java:6494)
                 at java.lang.reflect.Method.invoke(Native Method)
                 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
W/ResourceType: No package identifier when getting value for resource number 0x00000258
W/ImageView: Unable to find resource: 600
             android.content.res.Resources$NotFoundException: Resource ID #0x258
                 at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:224)
                 at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
                 at android.content.res.Resources.getDrawable(Resources.java:819)
                 at android.content.Context.getDrawable(Context.java:605)
                 at android.widget.ImageView.resolveUri(ImageView.java:915)
                 at android.widget.ImageView.setImageResource(ImageView.java:477)
                 at com.android.volley.toolbox.ImageLoader$1.onResponse(ImageLoader.java:112)
                 at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:229)
                 at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:191)
                 at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:182)
                 at com.sunplus.suniq.adapter.CustomAdapter.getView(CustomAdapter.java:80)
                 at android.widget.AbsListView.obtainView(AbsListView.java:2365)
                 at android.widget.ListView.measureHeightOfChildren(ListView.java:1408)
                 at android.widget.ListView.onMeasure(ListView.java:1315)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                 at android.view.View.measure(View.java:22071)
                 at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1028)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
                 at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
                 at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
                 at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:809)
                 at android.view.View.measure(View.java:22071)
                 at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1059)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                 at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                 at com.android.internal.policy.DecorView.onMeasure(DecorView.java:724)
                 at android.view.View.measure(View.java:22071)
                 at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2422)
                 at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1504)
                 at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761)
                 at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
                 at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
W/ImageView:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                 at android.view.Choreographer.doCallbacks(Choreographer.java:723)
                 at android.view.Choreographer.doFrame(Choreographer.java:658)
                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                 at android.os.Handler.handleCallback(Handler.java:790)
                 at android.os.Handler.dispatchMessage(Handler.java:99)
                 at android.os.Looper.loop(Looper.java:164)
                 at android.app.ActivityThread.main(ActivityThread.java:6494)
                 at java.lang.reflect.Method.invoke(Native Method)
                 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
I/Ads: Starting ad request.
I/Ads: This request is sent from a test device.
I/zygote: JIT allocated 67KB for compiled code of void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/Choreographer: Skipped 33 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
I/Ads: Scheduling ad refresh 70000 milliseconds from now.
I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:280
                  Selected remote version of com.google.android.gms.ads.dynamite, version >= 280
I/Ads: Ad finished loading.
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
I/zygote: Do full code cache collection, code=469KB, data=292KB
I/zygote: After code cache collection, code=389KB, data=233KB
          JIT allocated 56KB for compiled code of void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
W/zygote: Attempt to remove non-JNI local reference, dumping thread
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
W/zygote: Attempt to remove non-JNI local reference, dumping thread
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
D/OpenGLRenderer: endAllActiveAnimators on 0xe6adc700 (MenuPopupWindow$MenuDropDownListView) with handle 0xd30ff080
D/EGL_emulation: eglMakeCurrent: 0xf00b21e0: ver 3 1 (tinfo 0xf008fa30)
I/Process: Sending signal. PID: 28712 SIG: 9
Application terminated.

2 个答案:

答案 0 :(得分:0)

如果您想要任何线性布局底部的静态横幅,您需要为listview赋予权重。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ListView
            android:id="@+id/simpleListView"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:divider="@color/material_blue_grey_800"
            android:dividerHeight="1dp"
            android:layout_weight="1" 
            android:footerDividersEnabled="false" />

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            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="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>

    </LinearLayout>
希望这对你有所帮助。

答案 1 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_fresher">

    <ListView
        android:id="@+id/simpleListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/adView"
        android:divider="@color/material_blue_grey_800"
        android:dividerHeight="1dp"
        android:footerDividersEnabled="false" />


    <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_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"></com.google.android.gms.ads.AdView>

</RelativeLayout>

在您的布局中使用此功能,这将完全解决您的问题。

希望它有用