android - 如何使用 XML 在视频 View 的顶部添加 Admob 广告?

标签 android xml admob android-videoview

这是我的 xml 脚本。我似乎无法弄清楚如何在我的视频 View 上显示 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>

目前是这样显示的

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

但我希望它是这样的

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

请帮忙。谢谢

最佳答案

试试这个版本。我去掉了一些不必要的属性,将 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>

关于android - 如何使用 XML 在视频 View 的顶部添加 Admob 广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9902602/

相关文章:

android - 使用 Intent.FLAG_ACTIVITY_MULTIPLE_TASK 安全吗?

xml - 为什么 xs :precisionDecimal part of the XSD1. 不是 1?

android - 我可以使用 admob 激励广告移除横幅广告吗?

ios - 横幅拥抱到底部

java - 在 Android 上对 UI 元素采用响应式(Reactive)编程有什么真正的好处吗?

Android - 没有发现重力左侧的抽屉 View

java - Admob 广告给出错误代码 2(不显示)

xml - 将标题或标题与图像对齐?

.net - 如何删除 XML 文件中的重复值并保留最后一个值?

android - 播放安装引用库