【问题标题】:AdMob banner at bottom - Converting Linearlayout to RelativeLayout底部的 AdMob 横幅 - 将 Linearlayout 转换为 RelativeLayout
【发布时间】:2015-06-30 15:28:32
【问题描述】:

我对安卓很陌生。我正在尝试在应用程序底部添加一个 admob 横幅,实际上是在两个活动中。我认为 Linearlayout 不是正确的做法。

  1. 所以请帮我将 Linearlayout 转换为 RelativeLayout。

同样在运行应用程序时,仅显示 activity_entry.xml 示例-google-banner。 view_home.xml 横幅只显示静态空白。

  1. 如何使横幅智能?我的意思是我希望它仅在要显示横幅时显示,而不是作为静态空白区域显示。

activity_entry.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/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

<include layout="@layout/view_toolbar"/>

<fragment
    android:id="@+id/entry_fragment"
    class="net.etuldan.sparss.fragment.EntryFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    android:layout_gravity="center_horizontal">
</com.google.android.gms.ads.AdView>

view_home.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:orientation="vertical"
tools:showIn="@layout/activity_home"
android:weightSum="1">

<include layout="@layout/view_toolbar"/>

<fragment
    android:id="@+id/entries_list_fragment"
    android:name="net.etuldan.sparss.fragment.EntriesListFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    android:layout_gravity="center_horizontal">
</com.google.android.gms.ads.AdView>

【问题讨论】:

    标签: android xml android-layout admob adbannerview


    【解决方案1】:

    以下是一些获得您想要的东西的提示:

    在这里寻找使其成为相对布局:adMob | Smart banner at bottom?

    基本上,关键代码是你应该有

    android:layout_alignParentBottom="true"
    

    如果有帮助,你可以嵌套你的布局......或者没有。

    第二部分:考虑使用 adListener 并使用 onReceiveAd() 和 onFailedToReceiveAd() 来动态设置布局格式。

    在这里查看关于 adListener 的一些要点:

    How to know if AdMob ad has been loaded

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多