2012-03-28 76 views
1

这是我的xml脚本。我似乎无法弄清楚如何在我的videoview上显示admob广告。以下是我的xml代码。如何在使用XML的videoview中添加Admob广告?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res/com.gallery.video" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="bottom" > 

    <com.google.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="myid" 
    android:gravity="top" /> 


    <VideoView android:id="@+id/VideoView" 
      android:layout_width="fill_parent" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="false" 
      android:layout_alignParentBottom="false" 
      android:layout_height="wrap_content"> 
    </VideoView> 
</RelativeLayout> 

目前它显示像这样

http://img442.imageshack.us/img442/563/img1nve.jpg

但我想它是这样

http://img854.imageshack.us/img854/1614/img2bv.jpg

请帮助。谢谢

回答

1

试试这个版本。我拿出了一些不必要的属性,将AdMob广告对齐到屏幕的顶部,并通过android:layout_above属性将视频设置为低于广告。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res/com.gallery.video" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="myid" 
     android:layout_alignParentTop="true" /> 

    <VideoView android:id="@+id/VideoView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/adView" /> 
</RelativeLayout> 
1

您应该将属性android:layout_weight =“1”添加到VideoView标记。请参阅以下代码:

<VideoView android:id="@+id/VideoView" 
      android:layout_width="fill_parent" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentBottom="true" 
      android:layout_height="fill_parent" 
      android:layout_weight="1"> 
    </VideoView> 

我希望这可能对您有所帮助。

+0

谢谢NewBi。但它似乎也没有工作。 :) – 2012-03-28 07:22:40