1

我有课:

class AdmobAds
{
   private static final int ADVIEW_NOT_INITIALIZED = 1;
   private AdView adView;

   public int InitAds(final String pub_id)
   {
    LoaderActivity.m_Activity.runOnUiThread(new Runnable() {
@Override
public void run() {

adView = new AdView(LoaderActivity.m_Activity, AdSize.BANNER, pub_id);
adView.loadAd(new AdRequest());
LoaderActivity.m_Activity.addContentView(adView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
});
       return 0;
   }
   public int ShowAds()
   {
if(adView!=null){
LoaderActivity.m_Activity.runOnUiThread(new Runnable() {
@Override
public void run() {
adView.setVisibility(View.VISIBLE);
}});
} else { 
return ADVIEW_NOT_INITIALIZED; 
}

       return 0;
   }
   public int HideAds()
   {
if(adView!=null){
LoaderActivity.m_Activity.runOnUiThread(new Runnable() {
@Override
public void run() {
adView.setVisibility(View.INVISIBLE);
}});
} else { 
return ADVIEW_NOT_INITIALIZED; 
}
       return 0;
   }
}

我需要将 AdMob 横幅放置在已确定的位置 ix 和 iy 中。当我尝试添加 Layout 时,我们在其中放置了一个横幅应用程序。

应用写在Marmalade SDK上,所以用不上XML,一点经验也不能让我自己处理问题。

4

1 回答 1

1

这是我用于在顶部显示广告的内容:-

adView = new AdView(LoaderActivity.m_Activity,AdSize.BANNER, appKeyFinal);      
RelativeLayout layout = new RelativeLayout(LoaderActivity.m_Activity);
RelativeLayout.LayoutParams parentParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);

RelativeLayout.LayoutParams adNinjaLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adNinjaLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
LoaderActivity.m_Activity.addContentView(layout,parentParams);
adView.loadAd(adRequest);

我希望这会有所帮助。

于 2013-01-23T06:34:12.730 回答