【问题标题】:How to display banner ad in the bottom of all pages in my android application如何在我的 android 应用程序的所有页面底部显示横幅广告
【发布时间】:2014-04-29 05:59:18
【问题描述】:

我在主页底部有横幅广告,如下所示,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="0dp"
    tools:context=".MainActivity" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:contentDescription="@string/background"
        android:scaleType="fitXY"
        android:src="@drawable/bg" />

    <RelativeLayout
        android:id="@+id/riverLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/navBar"
        android:background="@drawable/item_bg"
        android:paddingBottom="10dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="0dp" >

        <ImageView
            android:id="@+id/riverImage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:contentDescription="@string/river_image_desc" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/riverImage"
            android:layout_marginLeft="5dp"
            android:text="@string/river_text"
            android:textColor="#4494CA"
            android:textSize="17sp"
            android:textStyle="bold" />

        <com.scringo.ScringoCommentButton
            android:id="@+id/riverCommentButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginTop="5dp"
            android:layout_below="@id/riverImage"
            android:layout_marginRight="50dp" />

        <com.scringo.ScringoLikeButton
            android:id="@+id/riverLikeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/riverCommentButton"
            android:layout_below="@id/riverImage"
            android:layout_marginTop="5dp"
            android:layout_marginRight="10dp" />
    </RelativeLayout>

    <Button
        android:id="@+id/riverFeedButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/riverLayout"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:text="@string/river_button_text" />

    <Button
        android:id="@+id/openChatRoomButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/riverFeedButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/discover" />

    <Button
        android:id="@+id/openInboxButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/openChatRoomButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/open_inbox_button_text" />

    <com.scringo.ScringoLeftRibbonButton
        android:id="@+id/activationRibbonLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="350dp" />

    <!--
        <com.scringo.ScringoRightRibbonButton
        android:id="@+id/activationRibbonRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="350dp" />
    -->
    <RelativeLayout
    android:id="@+id/toplayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.mopub.mobileads.MoPubView
        android:id="@+id/adview"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="10dp"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@drawable/spacer_old"  />
    </RelativeLayout>
</RelativeLayout>

横幅广告视图

'<com.mopub.mobileads.MoPubView   ../>' 

应该在所有页面中显示静态/固定在应用程序每个页面的底部,这意味着我不应该在所有页面中添加这个视图,但它仍然应该显示在所有页面的底部(如图像从底部弹出)。 如何做到这一点

【问题讨论】:

  • 任何人请给出解决方案

标签: android android-layout android-listview mopub scringo


【解决方案1】:

android:layout_alignParentBottom 属性从com.mopub.mobileads.MoPubView 移至其父级RelativeLayout,如下所示

<RelativeLayout
    android:id="@+id/toplayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <com.mopub.mobileads.MoPubView
        android:id="@+id/adview"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/spacer_old" />
</RelativeLayout>

【讨论】:

  • 在当前代码中,横幅视图显示在底部本身,我的问题是即使通过启动另一个活动加载另一个 xml/布局,这个 MoPub 视图应该继续显示在底部,其余的新页面/布局应显示在此 Mopub 视图上方
  • 那么您将在每个 Activity 布局 XML 中添加此 XML sn-p。
【解决方案2】:

或者试试这个

    <com.mopub.mobileads.MoPubView
        android:id="@+id/adview"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/spacer_old" />
</RelativeLayout>
    android:id="@+id/toplayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="">

    <com.mopub.mobileads.MoPubView
        android:id="@+id/adview"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="10dp"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@drawable/spacer_old"  />
    </RelativeLayout>
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 2020-12-24
    • 2016-12-06
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-23
    • 1970-01-01
    相关资源
    最近更新 更多