如何让广告在不重叠的情况下显示在屏幕底部 [英] How to get ad to show at bottom of screen without overlap

查看:22
本文介绍了如何让广告在不重叠的情况下显示在屏幕底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 admob 广告横幅,我想将它放在屏幕底部,并在广告加载时调整其余内容的大小以填充可用空间.我看到了我想要发生的确切事情当我将广告放在线性布局的顶部,然后将我的内容高度设置为 fill_parent.这可以反向实现吗?当我将我的广告以 fill_parent 高度放在我的内容下方时,它不会显示,因为没有足够的空间.我有一个具有相对布局和底部边距的解决方案,以节省广告空间,但我不喜欢在广告加载之前存在的黑色空间(如果有的话).有什么想法吗?

I have an admob ad banner which I'd like to put at the bottom of my screen, and have the rest of the content resize to fill the available space when the ad loads in. I see the exact thing I want happen when I put the ad at the top of a linear layout and then have my content's height set to fill_parent. Is this possible to achieve in reverse? When I put my ad underneath my content with the fill_parent height, it doesn't show as there is not enough room. I have a solution with a relative layout and a margin on the bottom to save the space for the ad, but I don't like the black space that is there until the ad loads (if it does at all). Any ideas?

推荐答案

你可以通过使用 RelativeLayout 来做到这一点,而无需做一些骇人听闻的事情:

You can do that by using RelativeLayout without doing hackish stuff:

<?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>

如果广告由于某种奇怪的原因没有加载,ListView 将占用所有可用空间.另一方面,如果广告确实加载了,ListView 将不会与广告重叠.

If the ad does not load for some strange reason, the ListView will take all the available space. On the other hand, if the ad does load, the ListView won't be overlapped by the ad.

这篇关于如何让广告在不重叠的情况下显示在屏幕底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆