當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。