没有足够的空间在自定义对话框Android问题上显示广告

时间:2014-12-16 10:53:05

标签: android

我在自定义对话框中显示来自Admob的广告时出现问题。它表示没有足够的空间来展示广告,需要320x50dp,它有294x250dp。我使用的是自定义对话框,例如:

enter image description here

我认为问题出现在对话框本身,因为左右大小空白,但我不知道如何解决它。我要求提供任何可以帮助我正确展示广告的建议。 以下是我的xml代码,其中存在adview: http://pastebin.com/pHYbjtU1

2 个答案:

答案 0 :(得分:0)

试试此代码

<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:layout_width="fill_parent"
    android:layout_height="match_parent"
    tools:context="com.example.kaladont.PostGameScreen"
    android:gravity="center"

    >

    <RelativeLayout 
        android:layout_width="320dp"
        android:minWidth="320dp"
        android:layout_height="250dp"
        android:paddingBottom="0dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="0dp"
        android:background="@drawable/levelselectorbg"

        >

        <com.example.classes.FontImageButton
            android:id="@+id/nextLvlButton"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:textSize="16sp"
            android:layout_centerHorizontal="true"
            android:text="Next level"
            />

        <com.example.classes.MyTextView
            android:id="@+id/notifyTV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:textSize="55sp"
            android:text="Congrats!"
            android:textAppearance="?android:attr/textAppearanceLarge"
            />

        <com.example.classes.FontImageButton
            android:id="@+id/mainMenuButton"
            style="?android:attr/buttonStyleSmall"
            android:textSize="16sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/nextLvlButton"
            android:layout_alignBottom="@+id/nextLvlButton"
            android:layout_alignParentRight="true"
            android:text="Main Menu" />

        <com.example.classes.MyTextView
            android:id="@+id/scoreTV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/notifyTV"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:layout_below="@+id/gameGoalTV"
            android:layout_marginTop="22dp"
            android:textSize="33sp"
            android:text="Your score is: "
            android:textAppearance="?android:attr/textAppearanceMedium"
            />

        <com.example.classes.MyTextView
            android:id="@+id/gameGoalTV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/scoreTV"
            android:layout_below="@+id/notifyTV"
            android:layout_marginTop="24dp"
            android:layout_centerHorizontal="true"
            android:textSize="30sp"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceMedium"
            />

        <com.example.classes.FontImageButton
            android:id="@+id/restartButton"
            style="?android:attr/buttonStyleSmall"
            android:textSize="16sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/nextLvlButton"
            android:layout_alignBottom="@+id/nextLvlButton"
            android:layout_alignParentLeft="true"
            android:text="Restart"
            />

    </RelativeLayout>

    <com.google.android.gms.ads.AdView

        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-5651680025356127/9525960691 "
        />

</LinearLayout>

答案 1 :(得分:0)

我使用了普通的布局而不是对话框,现在可以使用了。