我見過很多應用在屏幕邊緣都有廣告。但是當我試圖將廣告放在佈局的絕對邊緣時,它會自動將它放在離邊緣幾分之一的位置。將adMob廣告設置到屏幕邊緣?
這是XML:
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, MY_DEVICE_ID"
app:adSize="BANNER"
app:adUnitId="MY_DEV_CODE" >
</com.google.ads.AdView>
完整的XML代碼:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tBtn1"
android:layout_alignBottom="@+id/tBtn1"
android:layout_toRightOf="@+id/tBtn1"
android:text="Record as long as the button is touched" />
<ToggleButton
android:id="@+id/tBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Off"
android:textOn="On" />
<Chronometer
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/recButton"
android:layout_centerHorizontal="true"
android:text="Chronometer"
android:layout_marginTop="10dp" />
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, MY_DEVICE_ID"
app:adSize="BANNER"
app:adUnitId="MY_DEV_ID" >
</com.google.ads.AdView>
<ImageButton
android:id="@+id/recButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@drawable/record_btn" />
你試過了layout_alignParentLeft =「true」嗎? –
您是否有父視圖的邊距或插圖? – JavaDM
@ WEBALDO.at不,我剛剛發佈了整個XML代碼,用於整個佈局。你可以檢查它 – Guy