我无法弄清楚这是如何完成的,因为它没有使用布局来充气视图,但是精灵.
我使用BaseGameActivity为我想要显示的每个场景创建我的应用程序.
在GreyStrip中,这是他们告诉您在应用程序中集成广告的方式.
Before adding calls in your application to GSSDK,you need to
incorporate the SDK into your AndroidManifest.xml. Add the following
in the section,replacing
with a package identifier that is unique to your application. This
Content Provider manages local storage of ad content,while the
Activity manages ad display.
<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>
To initialize the Greystripe SDK,call the initialize method at
startup. This should be done within your application’s onCreate()
method. This call will spawn a background thread to initialize our
activity,and then return control to your app. In this background,the
Greystripe activity will download ads as well as any SDK updates.
Parameters: ctx: Your application Context instance appId: Use the
appId provided during app registration. Providing an invalid appId
will cause the SDK to display error notification ads.
public static GSSDK initialize(Context ctx,String appId)
To use a banner,place the following in your main.xml file:
<view class="com.greystripe.android.sdk.BannerView" android:id="@+id/gsBanner" android:layout_width="320dp" android:layout_height="48dp"/>
To reference the banner view in code,use findViewById,as with any
main.xml element:
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();
}
});
解决方法
与@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类中.