我试图在AndEngine中使用Greystrip显示广告.
我无法弄清楚这是如何完成的,因为它不使用布局来扩充视图,但是精灵.
我使用BaseGameActivity为我想要显示的每个场景创建我的应用程序.
在GreyStrip中,这是他们告诉您在应用程序中集成广告的方式.
在将应用程序中的调用添加到GSSDK之前,需要将SDK合并到AndroidManifest.xml中.在该部分中添加以下内容,替换为应用程序特有的包标识符.此内容提供商管理广告内容的本地存储,而活动管理广告显示.
 <provider android:name="com.greystripe.android.sdk.AdContentProvider"
    android:authorities="<YOUR_APPLICATION_PACKAGE>.AdContentProvider"
android:multiprocess="true"
android:exported="false" />
<activity android:name="com.greystripe.android.sdk.AdView"
android:configChanges="keyboard|keyboardHidden|orientation" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
要初始化Greystripe SDK,请在启动时调用initialize方法.这应该在您的应用程序的onCreate()方法中完成.此调用将生成一个后台线程来初始化我们的活动,然后将控制权返回给您的应用程序.在此背景下,Greystripe活动将下载广告以及任何SDK更新.参数:ctx:您的应用程序上下文实例appId:使用应用程序注册期间提供的appId.提供无效的appId会导致SDK显示错误通知广告.
 public static GSSDK initialize(Context ctx, String appId)
要使用横幅,请将以下内容放在main.xml文件中:
<view class="com.greystripe.android.sdk.BannerView"
android:id="@+id/gsBanner"
android:layout_width="320dp"
android:layout_height="48dp"/>
要在代码中引用标题视图,请使用findViewById,与任何main.xml元素一样:
BannerView myBanner = (BannerView) findViewById(R.id.gsBanner);
要求添加电话
myBanner.refresh();
现在的问题是因为我没有xml布局我无法弄清楚我如何为广告视图的布局充气?
有人有主意吗?
编辑:
我见过有人在网上教程中这样做,但我怎样才能在andengine中充气呢?
try {
    String applicationId = Utils.scrapeIgnoreCase(externalParams, "<param name=\"id\">", "</param>");           
    GSSDK.initialize(context, applicationId);
    BannerView myBanner = new BannerView(context);          
    myBanner.setLayoutParams(view.getLayoutParams());
    myBanner.addListener(new GreyStripeBannerListener());           
    view.addView(myBanner);
    myBanner.refresh();
    myBanner.setOnClickListener(new  View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Click();
        }
    });
我正在使用AdMob但它应该是类似的.
与@Sergey Benner引用一样,您必须onSetContentView在活动中覆盖,然后RenderSurfaceView手动创建广告视图.
首先,创建一个FrameLayout包含AndEngine的视图和广告视图.添加AndEngine的视图并创建广告视图,然后将框架布局设置为内容视图.
@Override
protected void onSetContentView() {
    //Creating the parent frame layout:
    final FrameLayout frameLayout = new FrameLayout(this);
    //Creating its layout params, making it fill the screen.
    final FrameLayout.LayoutParams frameLayoutLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                    FrameLayout.LayoutParams.FILL_PARENT);
    //Creating the banner view.
    BannerView bannerView = new BannerView(this);
    //....
    //Do any initiallizations on the banner view here.
    //....
    //Creating the banner layout params. With this params, the ad will be placed in the top of the screen, middle horizontally.
    final FrameLayout.LayoutParams bannerViewLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT,
                    Gravity.TOP | Gravity.CENTER_HORIZONTAL);
    //Creating AndEngine's view.
    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine, this);
    //createSurfaceViewLayoutParams is an AndEngine method for creating the params for its view.
    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
            new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
    //Adding the views to the frame layout.
    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
    frameLayout.addView(bannerView, bannerViewLayoutParams);
    //Setting content view
    this.setContentView(frameLayout, frameLayoutLayoutParams);
}
将此方法放在您的BaseGameActivity班级中.
| 归档时间: | 
 | 
| 查看次数: | 6047 次 | 
| 最近记录: |