问题描述
我想显示AndEngine使用Greystrip广告。
我无法弄清楚如何做到这一点,因为它不使用布局膨胀的意见,但尚未精灵。
我使用BaseGameActivity创建为每个场景我想显示加上我的应用程序。
在GreyStrip这也是他们告诉你在你的应用程序中集成广告。
<提供机器人:名称=com.greystripe.android.sdk.AdContentProvider
机器人:当局=< YOUR_APPLICATION_PACKAGE> .AdContentProvider
机器人:多进程=真
机器人:出口=FALSE/>
<活动机器人:名称=com.greystripe.android.sdk.AdView
机器人:configChanges =键盘| keyboardHidden |定位>
<意向滤光器>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
公共静态GSSDK初始化(上下文CTX,字符串的appid)
<视图类=com.greystripe.android.sdk.BannerView
机器人:ID =@ + ID / gsBanner
机器人:layout_width =320dp
机器人:layout_height =48dp/>
BannerView myBanner =(BannerView)findViewById(R.id.gsBanner);
要申请增加了通话
myBanner.refresh();
现在的问题是,因为我没有一个XML布局我无法弄清楚如何膨胀的布局广告的看法?
任何人有什么想法?
编辑:
我见过有人做这样的教程在网上,但我怎么能吹这andengine?
尝试{
串的applicationID = Utils.scrapeIgnoreCase(externalParams,&所述; PARAM NAME = \标识\>中,&所述; /参数>中);
GSSDK.initialize(背景下,的applicationID);
BannerView myBanner =新BannerView(上下文);
myBanner.setLayoutParams(view.getLayoutParams());
myBanner.addListener(新GreyStripeBannerListener());
view.addView(myBanner);
myBanner.refresh();
myBanner.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
点击();
}
});
我使用AdMob的,但它应该是相似的。
像@Sergey贝内引用,你必须重写 onSetContentView
在您的活动,然后创建 RenderSurfaceView
和你手动广告视图。
首先,创建一个的FrameLayout
包含AndEngine的观点和广告视图。添加AndEngine的观点,并创建自己的广告图,然后设置框架布局的内容视图。
@覆盖
保护无效onSetContentView(){
//创建父框架布局:
最后的FrameLayout的FrameLayout =新的FrameLayout(本);
//创建它的布局参数,可以使其充满屏幕。
最后FrameLayout.LayoutParams frameLayoutLayoutParams =
新FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT);
//创建横幅视图。
BannerView bannerView =新BannerView(本);
// ....
//是否有任何initiallizations在这里的旗帜看法。
// ....
//创建横幅布局PARAMS。与此PARAMS,广告将被放置在屏幕的顶部,中间水平。
最后FrameLayout.LayoutParams bannerViewLayoutParams =
新FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.TOP | Gravity.CENTER_HORIZONTAL);
//创建AndEngine的观点。
this.mRenderSurfaceView =新RenderSurfaceView(本);
mRenderSurfaceView.setRenderer(mEngine,这一点);
// createSurfaceViewLayoutParams是AndEngine方法创建PARAMS其观点。
最后android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
新FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
//添加到框架布局的意见。
frameLayout.addView(this.mRenderSurfaceView,surfaceViewLayoutParams);
frameLayout.addView(bannerView,bannerViewLayoutParams);
//设置内容视图
this.setContentView(的FrameLayout,frameLayoutLayoutParams);
}
将这种方法在你的 BaseGameActivity
类。
I am trying to display an advertisement using Greystrip in AndEngine.
I cannot figure out how this is done because it doesnt use a Layout to inflate views, but yet sprites.
i use BaseGameActivity to create my application for each scene i would like to display adds on.
In GreyStrip this is how they tell you to integrate ads in your application..
<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>
public static GSSDK initialize(Context ctx, String appId)
<view class="com.greystripe.android.sdk.BannerView"
android:id="@+id/gsBanner"
android:layout_width="320dp"
android:layout_height="48dp"/>
BannerView myBanner = (BannerView) findViewById(R.id.gsBanner);
To request adds call
myBanner.refresh();
Now the problem is since i dont have an xml layout i cant figure out how i inflate the layout for the ad view?
Anyone have any ideas?
EDIT:
Ive seen someone do it like this in a tutorial online, but how can i inflate this in 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();
}
});
I'm using AdMob but it should be similar.
Like @Sergey Benner referenced, you have to override onSetContentView
in your activity, then create the RenderSurfaceView
and your ad view manually.
First of all, create a FrameLayout
to contain AndEngine's view and the ad view.Add AndEngine's view and create your ad view, then set the frame layout as the content view.
@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);
}
Place this method in your BaseGameActivity
class.
这篇关于显示广告在AndEngine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!