[英]How to add ad-mob (Advertisement banner) Top OR Bottom of the Imageview?
我有 3 個線性布局,第一個布局用於圖像視圖,第二個布局用於兩個按鈕,即我為admob
添加的下一個、上一個和第三個,但問題是我的admob(Advertisement)
為廣告占用了額外的空間,但我想顯示頂部或底部位置圖像,如何設置它的 XML?
我希望我的廣告橫幅在圖片上看起來像這樣,而不是占用額外的空間:
我的 XML:
< ?xml version="1.0" encoding="utf-8"? >
< LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:gravity="fill"
android:orientation="vertical"
android:weightSum="100">
<ImageView
android:id="@+id/idImageViewPic"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="100"
android:adjustViewBounds="true"
android:background="#000000"
android:maxHeight="91dip"
android:maxWidth="47dip"
android:padding="10dip"
android:src="@drawable/p1"
/>
<LinearLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="50dp"
>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="aasdf74546adsf"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
>
</com.google.ads.AdView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:id="@+id/bGeri"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#d6d6d6"
android:text="Previous"
android:textStyle="bold" >
</Button>
<Button
android:id="@+id/bIleri"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#d6d6d6"
android:text="Next"
android:textStyle="bold" >
</Button>
</LinearLayout>
</LinearLayout>
看看這個,它可能對你有幫助。
創建 xml 文件,例如。
主文件
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/idImageViewPic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/p1" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="a152fe7ceceb49a"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
</RelativeLayout>
現在像這樣在activity_main.xml 中包含這個main.xml 文件。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="vertical" >
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/main" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/bGeri"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#d6d6d6"
android:text="Previous"
android:textStyle="bold" >
</Button>
<Button
android:id="@+id/bIleri"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#d6d6d6"
android:text="Next"
android:textStyle="bold" >
</Button>
</LinearLayout>
希望這能解決您的問題
使用相對布局,並對齊父底部:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="aasdf74546adsf"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
>
</com.google.ads.AdView>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.