【问题标题】:Positioning admob advert to bottom of screen将 admob 广告定位到屏幕底部
【发布时间】:2017-07-02 11:15:06
【问题描述】:

我正在开发一个 android 项目,刚刚下载了最新版本的 admob sdk。

我正在尝试将广告置于屏幕底部,但似乎没有任何效果。

下面是布局的 XML 代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView android:id="@+id/password_noRecords"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center"
        android:text="There are currently\nno saved logins"
        android:textSize="20dp"
        android:textStyle="bold|italic"/>
    <ListView 
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </ListView>
        <com.google.ads.AdView android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            ads:adUnitId="MY_ID"
            ads:adSize="BANNER"
            ads:testDevices="TEST_EMULATOR, emulator-5554"
            ads:loadAdOnCreate="true">
        </com.google.ads.AdView>
</LinearLayout>

我已经尝试在高度上制作 ListView 和 LinearLayout fill_parent,但在 logcat 中说没有足够的空间来显示广告。

我还尝试将广告包装在线性布局中并说 align parent bottom = true 但这并没有什么不同。

相反,广告直接放置在列表视图的底部,因此如果列表视图为半空,则广告位于屏幕中间。

我想要的是广告始终在屏幕底部可见,无论列表视图有多大或多小。

感谢您提供的任何帮助。

【问题讨论】:

    标签: android admob


    【解决方案1】:

    将您的父布局更改为RelativeLayout

    在 adView 上使用 android:layout_alignParentBottom="true",在 ListView 上使用 android:layout_above="@+id/adView"

    根据需要在其余视图上使用 android:layout_below="@+id/xxxx",以使它们的行为与使用 LinearLayout 时的行为相同

    【讨论】:

    • 不是android:alignParentBottom="true",是android:layout_alignParentBottom="true"
    【解决方案2】:

    兄弟,您可能必须使用 .xml 文件的“设计”选项卡来定位广告。调整边距等...

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    相关资源
    最近更新 更多