2012-06-30 50 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

相关问题