我有课:

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的经验,一点经验也不允许我自己处理问题。

最佳答案

这是我用来在顶部显示广告的方式:-

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);


希望对您有所帮助。

关于java - 如何将admob不在屏幕顶部(在果酱橘子酱的Java类中),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14464646/

10-10 09:14