2013-02-02 61 views
2

我已經搜索了周圍,似乎無法找到答案這個問題的答案有效。Admob通過Adwhirl:沒有足夠的空間顯示廣告!想要:480,75,有:480,0

我得到的錯誤是「沒有足夠的空間來顯示廣告想:480,75,擁有:480,0」

看來,由於某種原因,我的廣告有沒有高度可用。

這個運行在HAXE NME和我的手機與Android是HTC One S(540x960)4.0.3

下面是Java代碼:

public class AdWhirl 
{ 
public static RelativeLayout adLayout; 
public static GameActivity activity; 
public static String code; 

public static void init(String code) 
{ 
    AdWhirl.code = code; 
    activity = GameActivity.getInstance(); 

    activity.runOnUiThread(new Runnable() 
    { 
     public void run() 
     { 
      adLayout = new RelativeLayout(activity); 

      //Nothing works till this is set. 
      AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5); 

      RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
      ViewGroup view = (ViewGroup) activity.getWindow().getDecorView(); 
      ViewGroup content = (ViewGroup) view.getChildAt(0); 
      content.addView(adLayout, p); 
     } 
    }); 
} 

public static void showAd(final int position) 
{ 
    if(activity == null) 
    { 
     return; 
    } 

    activity.runOnUiThread(new Runnable() 
    { 
     public void run() 
     { 
      AdWhirlLayout l = new AdWhirlLayout(activity, code); 
      l.setMaxHeight(75); //AdMob asks for this minimum height 

      RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

      //Bottom-Center 
      if(position == 0) 
      { 
       p.addRule(RelativeLayout.CENTER_HORIZONTAL); 
       p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
      } 

      //Top-Center 
      else 
      { 
       p.addRule(RelativeLayout.CENTER_HORIZONTAL); 
       p.addRule(RelativeLayout.ALIGN_PARENT_TOP); 
      } 

      adLayout.addView(l, p); 
     } 
    }); 
} 

public static void hideAd() 
{ 
    if(activity == null) 
    { 
     return; 
    } 

    activity.runOnUiThread(new Runnable() 
    { 
     public void run() 
     { 
      adLayout.removeAllViews(); 
     } 
    }); 
} 
} 

回答

0

沒有看到你的XML佈局,我可以只有大膽地猜測,但你會想你的XML看起來像下面這樣:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/main_relative_layout_ad" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    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" 
    tools:context=".GameActivity" > 

    <!-- Note the layout_above attribute, below --> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="10dp" 
     android:layout_above="@+id/adView" 
     android:gravity="center" 
     android:text="@string/your_text_here" /> 

    <!-- Note the alignParentBottom attribute, below --> 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="YOUR_PUBLISHER_ID" 
     ads:loadAdOnCreate="true" /> 

</RelativeLayout> 

你可能使用的佈局是貪婪的,因此被吸了所有可用空間。使用layout_above將強制佈局留下廣告空間。

請記住,第一條支持規則是GIGO。錯誤的或不完整的信息會導致答案不全或者根本沒有答案,正如您在198問題之前的197個觀點所表明的,他甚至不敢猜測答案。

相關問題