首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FrameLayout下面的Adview

FrameLayout下面的Adview
EN

Stack Overflow用户
提问于 2016-09-08 12:18:35
回答 1查看 656关注 0票数 0

我正在通过Fragments转换我的主要活动。目前,我正在从每个AdView调用一个新的Fragment,但我只想从主要活动调用一个AdView,该活动显示在所有Fragments上。

现在,我只需要知道如何让AdView不显示在FrameLayout中,因为现在它正在阻塞底部的内容。

那么,如何将AdView放在FrameLayout的内容之外/下面呢?

content_main.xml

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.MainActivity"
tools:showIn="@layout/app_bar_main">


<FrameLayout
    android:id="@+id/mainFrame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</FrameLayout>

<RelativeLayout

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/mainFrame">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_gravity="center"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

</RelativeLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-08 12:51:00

只使用单个Relative Layout作为Root Layout,然后在Frame Layout中使用android:layout_above="@+id/adView"

这是xml代码。

代码语言:javascript
复制
<RelativeLayout 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="match_parent">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/adView"
        android:background="@mipmap/ic_launcher" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39390718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档