如何让广告在屏幕底部显示而不重叠

Emm*_*sin 10 android admob android-linearlayout

我有我喜欢把我的屏幕的底部,并有其余内容调整大小以填充可用空间时,我看到我想要的确切的事情在广告加载,当我把它发生的AdMob广告横幅线性布局顶部的广告,然后将我的内容高度设置为fill_parent.这有可能反过来实现吗?当我使用fill_parent高度将广告置于我的内容下方时,由于没有足够的空间,因此无法显示.我有一个相对布局和底部边距的解决方案,以节省广告的空间,但我不喜欢广告加载前的黑色空间(如果它完全一样).有任何想法吗?

Cri*_*ian 31

你可以通过使用RelativeLayout而不做hackish东西来做到这一点:

<?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">
    <bla.bla.AdView
            android:id="@+id/ad"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#FF0000"/>
    <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@id/ad"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

如果广告由于某些奇怪的原因而未加载,ListView则会占用所有可用空间.另一方面,如果广告确实加载,则广告不会ListView重叠.