为什么我不能在ListView之后放置Adview?

esk*_*era 2 android listview adview

我正在测试Adview我的布局.如果我放置Adview之前ListView一切都很好,但如果我把它放在它之后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>
Run Code Online (Sandbox Code Playgroud)

K-b*_*llo 6

您将ListView's 设置layout_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" />
Run Code Online (Sandbox Code Playgroud)