Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用XML在视频视图中添加Admob广告?_Android_Xml_Admob_Android Videoview - Fatal编程技术网

Android 如何使用XML在视频视图中添加Admob广告?

Android 如何使用XML在视频视图中添加Admob广告?,android,xml,admob,android-videoview,Android,Xml,Admob,Android Videoview,这是我的xml脚本。我似乎不知道如何在我的视频视图上显示admob广告。下面是我的xml代码 <?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" andr

这是我的xml脚本。我似乎不知道如何在我的视频视图上显示admob广告。下面是我的xml代码

<?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>

现在是这样的

但我希望是这样


请帮忙。谢谢

您应该将属性android:layout\u 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>


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

试试这个版本。我去掉了一些不必要的属性,将AdMob广告与屏幕顶部对齐,并通过
android:layout_over
属性将视频设置在广告下方

<?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>