【问题标题】:Overlapping Admob ads on ImageView in android在 Android 中的 ImageView 上重叠 Admob 广告
【发布时间】:2014-06-02 12:37:39
【问题描述】:

我在 android xml 中使用了以下内容。每当我滚动页面时,admob 广告都会从底部与图像的某些部分重叠。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#31352e" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="match_parent"
                android:layout_height="330dp"
                android:background="@drawable/pic_one"
                android:scaleType="fitXY" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="fill_parent"
                android:layout_height="330dp"
                android:layout_margin="5dp"
                android:background="#fff"
                android:scaleType="fitXY"
                android:src="@drawable/pic_two" />

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="fill_parent"
                android:layout_height="330dp"
                android:layout_margin="5dp"
                android:background="#fff"
                android:scaleType="fitXY"
                android:src="@drawable/pic_three" />

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="fill_parent"
                android:layout_height="330dp"
                android:layout_margin="5dp"
                android:background="#fff"
                android:scaleType="fitXY"
                android:src="@drawable/pic_four" />

            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="fill_parent"
                android:layout_height="330dp"
                android:layout_margin="5dp"
                android:background="#fff"
                android:scaleType="fitXY"
                android:src="@drawable/pic_five" />
        </LinearLayout>
    </ScrollView>

    <com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ID here"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR" />

</RelativeLayout>

但是,广告仍然与 ImageView 重叠

如何在广告加载时调整屏幕?

【问题讨论】:

  • android:layout_above="@id/adView" 添加到 ScrollView.. 现在它会填充父级,因此会出现重叠。
  • @hypd09 谢谢伙计,它的工作。

标签: android imageview admob


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/g"
        android:gravity="center"
        android:orientation="horizontal" >

              <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/black"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/activity_main_content_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:paddingBottom="8dp"
                android:paddingTop="8dp"
                android:text="APPLICATION NAME"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>
    </LinearLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4.12"
        android:background="@color/white" >

        <ImageView
            android:id="@+id/Large_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/icn" />



         </RelativeLayout>

  <RelativeLayout
        android:id="@+id/rel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
        android:background="@color/darkblue" >

  <com.google.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
            android:id="@+id/ad"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
           ads:adSize="BANNER"
             ads:loadAdOnCreate="true"
            ads:adUnitId="MY KEY " />  
    </RelativeLayout>


</LinearLayout>

【讨论】:

    【解决方案2】:

    拥有 ImageView 广告的最佳方式是using FrameLayout, 它只会在当前布局之上创建一个图层

    【讨论】:

    • (这篇文章似乎没有为问题提供quality answer。请编辑您的答案,或者将其作为对问题的评论发布)。
    猜你喜欢
    • 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
    相关资源
    最近更新 更多