-
Notifications
You must be signed in to change notification settings - Fork 4
Banner Integration
liuluchao edited this page May 16, 2016
·
5 revisions
获取Banner样式广告步骤:
1:布局文件中定义一个容器 比如:FrameLayout、LinearLayout 等。
2:获取CMNativeBannerView对象,设置banner size,设置请求banner的posId,以及设置回调接口;
3:load banner ad;
4:回调成功之后,展示banner
5:退出该页面时销毁view;
1:设置布局文件
res/layout/native_ad_layout.xml
<FrameLayout
android:id="@+id/origin_picks"
...
/>
2:获取 CMNativeBannerView 同时设置各种该属性;
CMNativeBannerView bannerView = new CMNativeBannerView(this);
bannerView.setAdSize(CMBannerAdSize);
bannerView.setPosid(mAdPosid);
bannerView.setAdListener(new CMBannerAdListener() {
@Override
public void onAdLoaded(CMAdView ad) {
}
@Override
public void adFailedToLoad(CMAdView ad, int errorCode) {
}
@Override
public void onAdClicked(CMAdView ad) {
}
});
注:当前banner支持两种广告样式: 320*50;300*250;
3:load banner ad
bannerView.loadAd();
4:展示banner 样式广告
public void onAdLoaded(CMAdView ad) {
mLinearLayout.removeAllViews();
mLinearLayout.addView(ad);
}
5:销毁view
@Override
protected void onDestroy() {
super.onDestroy();
if(cmNativeBannerView != null){
cmNativeBannerView.onDestroy();
}
}