如何将广告添加到 Android 应用程序而不与我的内容重叠

2024-04-18

我正在向我的应用程序添加广告(这是我第一次),但它总是与我的内容重叠(即它显示在我的内容上方)。

我的 XML 是:

<?xml version="1.0" encoding="utf-8"?>


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


<LinearLayout android:layout_width="fill_parent"
                  android:id="@+id/home_layout"
                  android:orientation="vertical"
                  android:layout_height="wrap_content"
                  android:background="@drawable/background">

     <TextView
        android:id="@+id/my_text"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:text="TextView2"
        android:textColor="#ffffff" 
        android:textColorHighlight="#000000"
        android:shadowColor="#000000"
        android:shadowDx="3"
        android:shadowDy="-3"
        android:shadowRadius="1.5"
        android:fadingEdge="horizontal"
        android:typeface="serif"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        />

</LinearLayout>   





<LinearLayout 
                  xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
                  android:layout_width="fill_parent"
                  android:id="@+id/ad_layout"
                  android:layout_height="wrap_content"
                  android:layout_alignParentBottom="true"
                >
<com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="a14f26e5d930307"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, 33334750709D00EC"
                         ads:loadAdOnCreate="true"/>
    </LinearLayout>


</RelativeLayout>

广告显示在屏幕底部,但隐藏了 TextView 的末尾! 有什么想法可以做到这一点而不与 TextView 重叠吗?

提前致谢 :)


您可以使用如下所示的结构。将 adView 对齐到android:layout_alignParentBottom="true"并将 LinearLayout 的属性设置为android:layout_above="@id/adView".

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidsam="http://schemas.android.com/apk/res/com.jameselsey"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxxxxxxxx"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR" />

    <LinearLayout
        android:id="@+id/home_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/adView"
        android:background="@drawable/background"
        android:orientation="vertical" >

        <!-- Your layout components should be here-->

    </LinearLayout>

</RelativeLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将广告添加到 Android 应用程序而不与我的内容重叠 的相关文章

  • 为什么 cordova.file.documentsDirectory 为空?

    我正在尝试使用 cordova plugin file transfer 在http ngcordova com docs plugins fileTransfer http ngcordova com docs plugins fileT
  • Kapt 未在即时应用程序功能模块中生成类

    我在我的 Android 应用程序中使用 dagger2 即使没有错误 它也不会生成匕首组件类 我已经在设置中启用了注释处理器并重新启动了我的 android studio 但这对我来说不起作用 我也读过这个帖子Dagger2 不生成 Da
  • 使用 GoogleServices 插件时忽略 Gradle ArchivesBaseName

    我经常使用 archivesbasename 来重命名我的输出 apk 但自从使用 google services 插件后 它就被忽略了 我能做些什么来让它再次工作吗 下面附上了我完整的 build gradle 感谢您的指点 apply
  • 在名称中使用时间戳时,Android Studio 在构建后无法启动应用程序

    我遇到了 gradle 和 Android Studio 的问题 该问题仅在 Android Studio 中构建时出现 BuildServer 和 Commandline 工作正常 applicationVariants all vari
  • Android自定义控件命名空间问题

    我一直在为 Android 开发自定义控件 尽管我尝试按照建议进行操作here https stackoverflow com questions 4495511 how to pass custom component parameter
  • Google Play 商店中基于服务的 Android 应用程序

    我正在开发一个应用程序 该应用程序仅包含一些服务 没有任何活动 即没有 UI 基本上 当用户在他 她的设备上安装应用程序时 我希望有 2 到 3 个服务在后台运行 对此我有几个疑问 应用程序安装后我的服务将如何启动 我的BroadcastR
  • 如何使用retrofit2进行GET请求?

    我有一个在本地主机上运行的安静的 Web 服务 我想在该剩余 URL 上发出 Retrofit2 GET 请求 MainActivity java private void requestData public static final S
  • Android Manifest 自动生成无效权限

    我不小心在 Android 清单中输入了无效的权限名称 并且无法将其删除 这是我的清单代码
  • 毕加索磁盘缓存

    我正在使用 Picasso 从 URL 加载图像 Picasso with getApplicationContext load product getImageUrl into imageView 据我所知 每次都会访问该网址 而不是缓存
  • 如何将 Android Instrumentation 测试推送到模拟器/设备?

    我正在尝试使用 Ubuntu 9 04 中的命令行 shell 在 Android 模拟器上运行 Webkit 布局测试 adb s emulator 5554 shell am instrument w com android dumpr
  • Android CursorAdapter、ListView 和后台线程

    我一直在开发的这个应用程序有包含数兆字节数据的数据库可供筛选 许多活动只是列表视图 通过数据库中的各个级别的数据下降 直到到达 文档 即从数据库中提取并显示在手机上的 HTML 我遇到的问题是 其中一些活动需要能够通过捕获击键并重新运行带有
  • 在后台服务中持续获取位置更新

    我正在开发需要在后台服务中持续获取位置更新的应用程序 我已经使用了它正在使用的后台粘性服务 但是 即使我添加了启动广播并在那里启动了服务 启动完成后服务也没有启动 服务启动并立即被杀死 另外 这不适用于奥利奥 服务在应用程序关闭几分钟后停止
  • 如何在android中画一条曲线?

    我是 Android 新手 正在开发一个关于绘制线条的示例项目 我想画一条连接两点的曲线或高架线 x1 y1 and x2 y2 我试过canvas drawArc 方法 但是RectF内的值drawArc方法只是圆的 x y 中心点 它在
  • 使用 UPI url 调用 PSP 应用程序

    我正在尝试创建一个商家应用程序 它将根据 NPCI 的指南生成一个 url 此 url 将作为意图共享 并且 PSP 应用程序 任何注册的银行应用程序 应该能够侦听该 url 并被调用 我已经形成了这样的网址 upi pay pa icic
  • 有没有办法在多个嵌套的 RecyclerView 之间共享同一个 LayoutManager

    我正在开发一个显示游戏列表的应用程序 在每个游戏的 itemView 内 我还有一个要显示的视频列表 预览和结构如下 我部署了一个RecyclerView作为窗口根视图 然后对于视频 我使用网格样式的RecyclerView来显示 所以这里
  • BitmapFactory.decodeResource() 忽略 jpg 图像的 inPreferredConfig 选项

    我尝试将jpeg资源图像加载到ARGB 8888格式的位图 BitmapFactory Options opts new BitmapFactory Options opts inPreferredConfig Bitmap Config
  • 使用 RecyclerView.Adapter 在 onBindViewHolder() 内设置 onItemClickListener

    我有一个自定义对象 学生班 public class Student private String name private String age public String getName return name public void
  • 制作弹跳动画

    我想做图层的弹跳动画 我已经完成了该图层从右到中心的操作 现在我想将其向后移动一点 然后回到中心 这会产生反弹效果 我想我可以用这样的翻译来做到这一点
  • 如何从灰度字节缓冲区图像创建位图?

    我正在尝试使用新的 Android 人脸检测移动视觉 API 来处理帧图像 所以我创建了自定义检测器来获取帧并尝试调用 getBitmap 方法 但它为空 所以我访问了帧的灰度数据 有没有办法从它或类似的图像持有者类创建位图 public
  • Android Espresso - 如果未选中,请单击复选框

    I have onView withId R id check box perform click 但我只想在尚未选中该复选框时执行此操作 我怎样才能在浓缩咖啡中做到这一点 我还想根据其之前的状态来切换复选框 开关 起初 我尝试用此方法打开

随机推荐