布局问题中的广告横幅尺寸

时间:2013-11-21 20:25:15

标签: android android-layout android-fragments admob

我的app中有简单的布局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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxx" />

    <RelativeLayout
        android:id="@+id/searchTextLayout"
        android:layout_width="match_parent"
        android:layout_height="50dip"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="5dip"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:layout_marginTop="80dip"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/button1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:background="@null"
            android:onClick="geoLocate"
            android:scaleType="fitCenter"
            android:src="@drawable/but" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@id/button1"
            android:background="@drawable/sback"
            android:hint="Wprowadź swój adres"
            android:padding="8dp"
            android:textColor="@android:color/black" />
    </RelativeLayout>

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

但是当我在log cat中运行我的应用程序时,我收到了这样的错误:“没有足够的空间来显示广告。需要480x75,但只有432x730”有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

在没有看到场景拍摄的情况下很难回答。如果我是你,并试图解决这个问题,我会从视图中删除很多,并继续重新引入部分视图,直到问题返回。然后您将知道视图中需要更改的内容。所以也许从这里开始建立备份

  ?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"


          ads:adUnitId="xxx" />

    </LinearLayout>

还要考虑使用dip单位而不是“match_parent”定义所有布局,直到找到问题为止。它会让你确切知道所有东西相互之间的显示大小。

希望这会有所帮助。

答案 1 :(得分:0)

几乎可以肯定,最外层的LinearLayout中的填充

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

删除/减少这些。

相关问题