我正在向我的应用添加广告(这是我的第一次),但它总是与我的内容重叠(即显示在我的内容上)。
我的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重叠?
提前致谢:)
答案 0 :(得分:4)
您可以使用下面给出的结构。将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>