2012-05-18 2 views
2

Я тестирую Adview на моем макете. Если я разместил Adview до ListView, все будет хорошо, но если я поместил его после ListView, он просто не появится.Почему я не могу разместить Adview после ListView?

Что случилось?

<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

Вы устанавливаете ListView «s layout_height к fill_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 поэтому ваше вертикальное пространство уже занято ListView ,,,

так делают Listview 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

C внесите свой макет в RelativeLayout и добавьте android:layout_above="@+id/adView" в ваш ListView. Я надеюсь помочь вам.

<?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> 
Смежные вопросы