2012-06-30 52 views
2

我正在開發一個android項目,並剛下載了admob sdk的最新版本。將admob廣告定位到屏幕底部

我想將廣告放置在屏幕的底部,但沒有任何我嘗試似乎工作。

下面是佈局的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="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <TextView android:id="@+id/password_noRecords" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:layout_gravity="center" 
     android:text="There are currently\nno saved logins" 
     android:textSize="20dp" 
     android:textStyle="bold|italic"/> 
    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
    </ListView> 
     <com.google.ads.AdView android:id="@+id/adView" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      ads:adUnitId="MY_ID" 
      ads:adSize="BANNER" 
      ads:testDevices="TEST_EMULATOR, emulator-5554" 
      ads:loadAdOnCreate="true"> 
     </com.google.ads.AdView> 
</LinearLayout> 

我曾試圖使ListView控件以及在高度,但隨後在logcat的是說,有沒有足夠的空間來展示廣告的LinearLayout FILL_PARENT 。

我也嘗試在線性佈局中包裝廣告,並說對齊parent bottom = true,但這並沒有什麼區別。

而是將廣告直接放置在列表視圖的底部,因此如果列表視圖爲半空,則廣告位於屏幕中間。

我想要的是廣告總是在屏幕底部可見,不管列表視圖有多大或多小。

感謝您提供的任何幫助。

回答

12

你的父母佈局改變對你的ListView上AdView的一個RelativeLayout

使用android:layout_alignParentBottom="true"android:layout_above="@+id/adView"。根據需要

使用android:layout_below="@+id/xxxx"對你的看法其餘使他們的行爲一樣與你LinearLayout

+0

它不是android:alignParentBottom =「true」,它是android:layout_alignParentBottom =「true」 – Marc

+0

好抓住@Marc,我在我的答案中糾正了它。 – FoamyGuy

-2

兄弟你可能必須使用.xml文件的設計選項卡來定位廣告。調整邊距等...

+0

嗨,歡迎來到堆棧溢出。請參閱[如何回答](https://stackoverflow.com/help/how-to-answer) – Maher

相關問題