gpt4 book ai didi

android - 如何在不与我的内容重叠的情况下向 Android 应用添加广告

转载 作者:搜寻专家 更新时间:2023-11-01 08:11:27 26 4
gpt4 key购买 nike

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

我的 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" 将您的 LinearLayout 对齐到此 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>

关于android - 如何在不与我的内容重叠的情况下向 Android 应用添加广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9149962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com