2012-03-28 40 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

相關問題