2012-05-18 41 views
2

我正在測試我的版面上的Adview。如果我把Adview放在ListView之前,一切都很好,但如果我把它放在ListView之後,它就不會顯示出來。爲什麼我不能在ListView之後放置Adview?

怎麼了?

<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="wrap_content" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="bottom" 
     android:background="@android:color/white" /> 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxx" 
     ads:testDevices="xxxx" /> 

</LinearLayout> 

回答

6

您設置ListViewlayout_heightfill_parent,因此將需要在佈局中所有剩餘的垂直空間。你的AdView就在那裏,它只是被ListView移出屏幕。

如果你要放置AdView底部,並有ListView採取所有剩餘的垂直空間,你可以用重物做到這一點:

<ListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="@android:color/white" /> 
+0

太棒了!謝謝@ K-ballo,我試過這段代碼,但我認爲我必須在AdView上使用它。現在工作正常。 – eskalera

+0

這工作安排用戶界面,但一旦廣告加載並顯示ListView滾動到數據的底部:-( –

+0

'android:transcriptMode'應該被禁用:-)現在它不再滾動 –

2

Listview height is fill parent所以你的垂直空間已經採取列表視圖,,,

所以讓列表視圖android:layout_weight="1"

<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="wrap_content" 
    android:orientation="vertical" > 

    <ListView android:layout_weight="1" 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="bottom" 
     android:background="@android:color/white" /> 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxx" 
     ads:testDevices="xxxx" /> 

</LinearLayout> 
1

ç將您的布​​局更改爲RelativeLayout並在您的ListView中添加android:layout_above="@+id/adView"。我希望能幫助你。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ListView 
     android:id="@+id/list_view" 
     android:layout_above="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:divider="@null" /> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxxx" /> 

</RelativeLayout> 
相關問題