简体   繁体   English

Android admob广告未展示

[英]Android admob ads not displaying

So I feel it might be a layout issue in my main.xml file. 所以我觉得这可能是main.xml文件中的布局问题。 I am in no way an xml expert. 我绝对不是xml专家。 I experimented with the test app from admob and was able to get it to display ads so I know it is not an issue with the publisher ID. 我试用了admob的测试应用程序,并使其能够展示广告,因此我知道这与发布商ID无关。 Below is the contents of my main.xml file: 以下是我的main.xml文件的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.project.testsoundboard"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tabhost" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
         <com.google.ads.AdView 
                       android:id="@+id/adView"
                       android:layout_width="320dip"
                       android:layout_height="48dip"
                      ads:adUnitId="a28d9e354361jf3"
                       ads:adSize="BANNER"/>
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <GridView 
            android:id="@+id/tab1"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:padding="2dp" android:verticalSpacing="2dp"
                android:horizontalSpacing="2dp" android:numColumns="2"
                android:stretchMode="columnWidth" android:gravity="center" />
            <GridView android:id="@+id/tab2"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:padding="2dp" android:verticalSpacing="2dp"
                android:horizontalSpacing="2dp" android:numColumns="2"
                android:stretchMode="columnWidth" android:gravity="center" />
            <GridView android:id="@+id/tab3"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:padding="2dp" android:verticalSpacing="2dp"
                android:horizontalSpacing="2dp" android:numColumns="2"
                android:stretchMode="columnWidth" android:gravity="center" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

Here is my attrs.xml: 这是我的attrs.xml:

 <?xml version="1.0" encoding="utf-8"?>
<resources>
 <declare-styleable name="com.google.ads.AdView">
  <attr name="adSize">
      <enum name="BANNER" value="1"/>
      <enum name="IAB_MRECT" value="2"/>
      <enum name="IAB_BANNER" value="3"/>
      <enum name="IAB_LEADERBOARD" value="4"/>
  </attr>
  <attr name="adUnitId" format="string"/>

I added the appropriate permissions in the manifest file as well 我也在清单文件中添加了适当的权限

There is spacing above the tabs from the layout_width and layout_height I specified in the main.xml layout file but nothing appears. 选项卡上方与在main.xml布局文件中指定的layout_width和layout_height之间有间距,但没有任何显示。

Any help or suggestions would be greatly appreciated. 任何帮助或建议,将不胜感激。

Might be that your framelayout is also trying to fill parent, so even though you explicitly gave a size for your ad, it might be getting squeezed out. 可能是因为您的框架布局也在尝试填充父级,所以即使您明确指定了广告尺寸,也可能会被挤出。

If that doesn't help, you might try removing everything except for the ad, and ad the other elements until you find what causes it to break. 如果这样做没有帮助,您可以尝试删除除广告以外的所有内容,并为其他元素添加广告,直到找到导致广告崩溃的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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