我想讓Google Admob廣告顯示在由ListView組成的應用程序的主屏幕上。不幸的是,ListView佔據了屏幕上的所有空間,然後廣告出現在屏幕的頂部。我試着把ListView放在頂部,後面跟着一個AdView,我也試着把AdView放在頂部,然後是ListView,但沒有任何效果。嘗試在Android中使用Admob Adview時佔用所有空間的ListView
如果我將包含ListView的LinearLayout的大小設置爲固定高度(例如,200px),那麼它會限制大小並修復問題,但我不想這樣做,因爲Android的屏幕高度設備差異很大。沒有辦法告訴ListView在沒有設置固定大小的情況下不佔用所有空間?
我的代碼是下面,我會感謝任何幫助:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_alignParentTop="true"
android:id="@+id/ad_layout"
android:orientation="vertical"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentBottom="true"
android:layout_below="@+id/ad_layout"
android:orientation="vertical"
android:gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/no_hosts"/>
</LinearLayout>
</RelativeLayout>
太棒了;那就是訣竅。非常感謝 :) – paul88888 2011-06-16 08:13:46