当前位置: 首页>>代码示例>>Java>>正文


Java AdView.setLayerType方法代码示例

本文整理汇总了Java中com.google.android.gms.ads.AdView.setLayerType方法的典型用法代码示例。如果您正苦于以下问题:Java AdView.setLayerType方法的具体用法?Java AdView.setLayerType怎么用?Java AdView.setLayerType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.ads.AdView的用法示例。


在下文中一共展示了AdView.setLayerType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onActivityCreated

import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle bundle) {
    super.onActivityCreated(bundle);

    // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
    // values/strings.xml.
    mAdView = (AdView) getView().findViewById(R.id.adView);

    // The current version of AdMob breaks rotation animations on some devices.
    // Setting the layer type of the ad to Software or Hardware fixes it.
    // https://code.google.com/p/android/issues/detail?id=70914
    mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    // Create an ad request.
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(getString(R.string.test_device_id))
            .build();

    // Start loading the ad in the background.
    mAdView.loadAd(adRequest);
    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            mAdView.setVisibility(View.GONE);
            super.onAdFailedToLoad(errorCode);
        }
    });
}
 
开发者ID:TylerCarberry,项目名称:2048-Battles,代码行数:30,代码来源:AdFragmentGame.java

示例2: onActivityCreated

import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle bundle) {
    super.onActivityCreated(bundle);

    // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
    // values/strings.xml.
    View rootView = getView();

    if(rootView != null)
        mAdView = (AdView) rootView.findViewById(R.id.adView);

    // The current version of AdMob breaks rotation animations on some devices.
    // Setting the layer type of the ad to Software or Hardware fixes it.
    // https://code.google.com/p/android/issues/detail?id=70914
    mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    // Create an ad request.
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(getString(R.string.test_device_id))
            .build();

    // Start loading the ad in the background.
    mAdView.loadAd(adRequest);
    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            mAdView.setVisibility(View.GONE);
            super.onAdFailedToLoad(errorCode);
        }
    });
}
 
开发者ID:TylerCarberry,项目名称:2048-Battles,代码行数:33,代码来源:AdFragmentMain.java

示例3: create

import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
/**
 * Create the Banner
 * 
 */
public void create() {
   	mContext.log(CLASS+"create adview");

   	// Create the new adView
	mAdView = new AdView(mActivity);
	mAdView.setAdUnitId(mAdMobId);
	mAdView.setAdSize(mAdMobSize);

	// Force Hardware Rendering on supported devices
   	if (Build.VERSION.SDK_INT >= 11) {
   		mAdView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
   	}
   	mContext.log(CLASS+"set adview Listeners");
	// Add the Listener for the adView
	mAdView.setAdListener(new AdListener() {
		/**
		 * onAdLoaded Callback
		 */
           @Override
           public void onAdLoaded() {
           	// Dispatch event to AS
           	mContext.dispatchStatusEventAsync(ExtensionEvents.BANNER_LOADED, mBannerId);
           }
		/**
		 * onAdFailedToLoad Callback
		 */
           @Override
           public void onAdFailedToLoad(int error) {
           	// Dispatch event to AS
           	mContext.dispatchStatusEventAsync(ExtensionEvents.BANNER_FAILED_TO_LOAD, mBannerId);
           }
		/**
		 * onReceiveAd Callback
		 */
           @Override
           public void onAdOpened() {
           	// Dispatch event to AS
           	mContext.dispatchStatusEventAsync(ExtensionEvents.BANNER_AD_OPENED, mBannerId);
           }
		/**
		 * onReceiveAd Callback
		 */
           @Override
           public void onAdClosed() {
           	// Dispatch event to AS
           	mContext.dispatchStatusEventAsync(ExtensionEvents.BANNER_AD_CLOSED, mBannerId);
           }
		/**
		 * onReceiveAd Callback
		 */
           @Override
           public void onAdLeftApplication() {
           	// Dispatch event to AS
           	mContext.dispatchStatusEventAsync(ExtensionEvents.BANNER_LEFT_APPLICATION, mBannerId);
           }
       });
	
	// Set the adView visibility as hidden by default
	mAdView.setVisibility(View.GONE);
   	mContext.log(CLASS+"set adview Layout");
	
	// Set the view Position in the layout
	RelativeLayout.LayoutParams layoutParams;
	if(mAdPositionType == POS_ABSOLUTE){
		layoutParams = getAbsoluteParams();
	}else{
		layoutParams = getRelativeParams();
	}
	mAdLayout.addView(mAdView, layoutParams);
   	mContext.log(CLASS+"set adview Request");
	// Create the Banner Request for adMob
	AdRequest request = mContext.getRequest();

	// Load the ad
   	mContext.log(CLASS+"load adview Request");
	mAdView.loadAd(request);
}
 
开发者ID:mnashwan,项目名称:AdMobAne,代码行数:82,代码来源:AdMobBanner.java


注:本文中的com.google.android.gms.ads.AdView.setLayerType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。