2011-02-24 64 views
0

我正在尝试将AdMob集成到我的Android应用程序中,并且可以在模拟器中使用默认样本布局代码将AdMob定位在屏幕底部时正常工作每当我尝试将其放置在屏幕的顶部时,都不会投放广告。我已经读到,这可能是因为广告缺乏空间。Android AdMob屏幕顶部屏幕不工作

此代码在屏幕的底部(纵向):

<RelativeLayout 
    android:id="@+id/InnerRelativeLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" > 

    <com.admob.android.ads.AdView 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     app:backgroundColor="#000000" 
     app:primaryTextColor="#FFFFFF" 
     app:secondaryTextColor="#CCCCCC" 
     android:layout_alignParentBottom="true" 
    /> 

</RelativeLayout> 

但是,当我试图将其在顶部位置不起作用

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
android:id="@+id/widget40" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res/com.myapp.xxxx" 
> 

<RelativeLayout 
     android:id="@+id/InnerRelativeLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" > 

     <com.admob.android.ads.AdView 
      android:id="@+id/ad" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      app:backgroundColor="#000000" 
      app:primaryTextColor="#FFFFFF" 
      app:secondaryTextColor="#CCCCCC" 
      android:layout_alignParentTop="true" 
     /> 
    </RelativeLayout> 

<TextView 
    android:id="@+id/widget28" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Input Amount:" 
    android:layout_marginLeft="10dip" 
    android:layout_marginTop="10dip" 
    android:layout_marginRight="10dip" 
    android:textSize="16dip" 
    android:textStyle="bold"> 
</TextView> 

任何帮助,将不胜感激。

感谢阿龙

回答

1

如果你总是想显示在屏幕的上方,那么你可能要考虑使用RelativeLayout的。

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

<com.admob.android.ads.AdView 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     app:backgroundColor="#000000" 
     app:primaryTextColor="#FFFFFF" 
     app:secondaryTextColor="#CCCCCC" 
     android:layout_alignParentTop="true" 
    /> 

<!-- TextView below that --> 

<TextView 
android:id="@+id/widget28" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Input Amount:" 
android:layout_marginLeft="10dip" 
android:layout_marginTop="10dip" 
android:layout_marginRight="10dip" 
android:layout_below="@id/ad" 
android:textSize="16dip" 
android:textStyle="bold"> 
</TextView> 

</RelativeLayout> 
0

确保您没有缩放模拟器屏幕,因为这已经导致我的问题,从而导致广告不出现。我还必须设置广告layout_height =“50dip”,以确保广告不会突然将其他视图(控件)向下拖动屏幕并弄乱布局。