【问题标题】:Android listview overlaps adviewAndroid listview 与 adview 重叠
【发布时间】:2014-01-09 19:50:47
【问题描述】:

在我的xml 中,我有一个listview 和一个adview (admob)

如果我将adview 放在顶部一切正常,但如果我将它放在底部listview 下方,它就会消失。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

        <com.google.ads.AdView
        android:id="@+id/ad"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true" 
        android:layout_gravity="center"
        android:layout_margin="5dp">
    </com.google.ads.AdView>

</LinearLayout>

【问题讨论】:

    标签: android xml listview android-listview


    【解决方案1】:

    更改列表视图的布局权重:

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>
    

    【讨论】:

    • 错误:在包 'android' 中找不到属性 'weight' 的资源标识符
    • 已修复。应该是layout_weight
    • 其实我觉得layout_height应该是0而不是wrap_content。可能会按原样工作。给它(而不是其他兄弟)一个 layout_weight 告诉它在计算完所有 layout_heights 后额外占用剩余的可用空间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 2016-10-14
    • 2015-08-21
    • 2012-12-25
    • 2021-07-18
    相关资源
    最近更新 更多