當前位置: 首頁>>代碼示例>>Java>>正文


Java AdView.setAdSize方法代碼示例

本文整理匯總了Java中com.google.android.gms.ads.AdView.setAdSize方法的典型用法代碼示例。如果您正苦於以下問題:Java AdView.setAdSize方法的具體用法?Java AdView.setAdSize怎麽用?Java AdView.setAdSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.gms.ads.AdView的用法示例。


在下文中一共展示了AdView.setAdSize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addAds

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void addAds() {
    // add AdMob
    AdView adView = new AdView(this);
    adView.setAdUnitId(AD_UNIT_ID);
    adView.setAdSize(AdSize.SMART_BANNER);

    LinearLayout.LayoutParams adLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    adView.setLayoutParams(adLayoutParams);

    // 広告表示位置は畫麵下部
    LinearLayout layout = new LinearLayout(this);
    layout.addView(adView);
    layout.setGravity(Gravity.BOTTOM);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    addContentView(layout, layoutParams);

    // load ad
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
}
 
開發者ID:tmurakam,項目名稱:presentationtimer-android,代碼行數:22,代碼來源:PrefActivity.java

示例2: createAdView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private AdView createAdView() {
    mAdView = new AdView(this);
    mAdView.setAdSize(AdSize.LARGE_BANNER);

    // setup "testing" banner type
    boolean isStoreBuild = BuildConfig.FLAVOR.equals("playstore") && BuildConfig.BUILD_TYPE.equals("release");
    String adUnitId = isStoreBuild ? AD_UNIT_ID : "ca-app-pub-3940256099942544/6300978111";

    mAdView.setAdUnitId(adUnitId);
    mAdView.setId(View.generateViewId()); // this is an arbitrary id, allows for relative positioning in createGameView()
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    mAdView.setLayoutParams(params);
    mAdView.setBackgroundColor(Color.BLACK);

    return mAdView;
}
 
開發者ID:tgobbens,項目名稱:fluffybalance,代碼行數:20,代碼來源:AndroidLauncher.java

示例3: initAdvertise

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void initAdvertise() {
    AdView mAdView = new AdView(this);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    mAdView.setAdUnitId("ca-app-pub-3406938862137540/3927782716");
    mAdView.setBackgroundColor(Color.BLACK);
    AdRequest adRequest = new AdRequest.Builder().build();
    double dppxl = (1 * (Resources.getSystem().getDisplayMetrics().densityDpi / 160f));
    int v = this.getResources().getDisplayMetrics().heightPixels;
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.act_main_baseLayout);
    layout.addView(mAdView, params);
    if(v/dppxl > 720)
        mAdView.setAdSize(AdSize.BANNER);
    else
      mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.loadAd(adRequest);
}
 
開發者ID:inffeldgroup,項目名稱:sw2016,代碼行數:18,代碼來源:MainActivity.java

示例4: ADView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void ADView() {

        LinearLayout adBannerLayout = (LinearLayout) findViewById(R.id.footerLayout);

        adView = new AdView(this);
        adView.setAdUnitId(Constant.ADMob_BuddhaVoice);
        adView.setAdSize(AdSize.SMART_BANNER);
        adBannerLayout.addView(adView);

        AdRequest adRequest;

        if (BuddhaVoice.APPDEBUG) {
            //Test Mode
            adRequest = new AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .addTestDevice(Constant.ADMob_TestDeviceID)
                    .build();
        } else {

            adRequest = new AdRequest.Builder().build();

        }
        adView.loadAd(adRequest);

    }
 
開發者ID:ccjeng,項目名稱:BuddhaVoice,代碼行數:26,代碼來源:VoiceListener.java

示例5: ADView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void ADView() {

        LinearLayout adBannerLayout = (LinearLayout) findViewById(R.id.footerLayout);

        adView = new AdView(this);
        adView.setAdUnitId(Constant.ADMob_BuddhaVoiceMain);
        adView.setAdSize(AdSize.SMART_BANNER);
        adBannerLayout.addView(adView);

        AdRequest adRequest;

        if (BuddhaVoice.APPDEBUG) {
            //Test Mode
            adRequest = new AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .addTestDevice(Constant.ADMob_TestDeviceID)
                    .build();
        } else {

            adRequest = new AdRequest.Builder().build();

        }
        adView.loadAd(adRequest);

    }
 
開發者ID:ccjeng,項目名稱:BuddhaVoice,代碼行數:26,代碼來源:MainActivity.java

示例6: showGoogleAdMobAds

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void showGoogleAdMobAds(Activity activity) {

        try {
            AdView adView = new AdView(activity);
            adView.setAdUnitId("ca-app-pub-5619114666968507/6860732934");
            adView.setAdSize(AdSize.BANNER);

            LinearLayout layout = (LinearLayout) activity.findViewById(R.id.adsLayout);
            // Add the adView to it
            layout.addView(adView);
            // Initiate a generic request.
            AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .addTestDevice(TESTDEVICE_SGS5)
                    .addTestDevice(TESTDEVICE_SGS3MINI)
                    .addTestDevice(TESTDEVICE_DUOS_Y).build();
            // Load the adView with the ad request.
            adView.loadAd(adRequest);
        } catch (Exception e) {
            Log.e(TAG, "Error while getting ads", e);
        }
    }
 
開發者ID:konir,項目名稱:RadioRecPlus,代碼行數:22,代碼來源:AdMob.java

示例7: loadAd

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void loadAd(View view) {
    //Init ad
    adView = new AdView(application);
    adView.setAdUnitId(ApiUtils.AD_UNIT_ID_MAIN);
    adView.setAdSize(AdSize.BANNER);

    //Init params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.setMargins(0, 0, 0, 24);
    adView.setLayoutParams(params);

    //Add to
    RelativeLayout rootContainer = (RelativeLayout) view.findViewById(R.id.rootContainer);
    rootContainer.addView(adView);

    AdRequest adRequest = new AdRequest.Builder().build();

    if (!DebugConfig.isDebug)
        adView.loadAd(adRequest);
}
 
開發者ID:almiso,項目名稱:CollageApp,代碼行數:24,代碼來源:FragmentMain.java

示例8: loadAd

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void loadAd(View view) {
    //Init ad
    adView = new AdView(application);
    adView.setAdUnitId(ApiUtils.AD_UNIT_ID_SEARCH_USER);
    adView.setAdSize(AdSize.BANNER);

    //Init params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.setMargins(0, 0, 0, 24);
    adView.setLayoutParams(params);

    //Add to container
    RelativeLayout rootContainer = (RelativeLayout) view.findViewById(R.id.rootContainer);
    rootContainer.addView(adView);

    //Add request
    AdRequest adRequest = new AdRequest.Builder().build();

    if (!DebugConfig.isDebug)
        adView.loadAd(adRequest);
}
 
開發者ID:almiso,項目名稱:CollageApp,代碼行數:25,代碼來源:FragmentSearchUserByNick.java

示例9: loadAd

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void loadAd(View view) {
    //Init ad
    adView = new AdView(application);
    adView.setAdUnitId(ApiUtils.AD_UNIT_ID_USER_PROFILE);
    adView.setAdSize(AdSize.BANNER);

    //Init params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.setMargins(0, 0, 0, 24);
    adView.setLayoutParams(params);

    //Add to container
    RelativeLayout rootContainer = (RelativeLayout) view.findViewById(R.id.rootContainer);
    rootContainer.addView(adView);

    //Add request
    AdRequest adRequest = new AdRequest.Builder().build();

    if (!DebugConfig.isDebug)
        adView.loadAd(adRequest);
}
 
開發者ID:almiso,項目名稱:CollageApp,代碼行數:25,代碼來源:FragmentUserProfile.java

示例10: setupAds

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void setupAds() {
   String admobAdUnitId = getString( R.string.main_activity_admob_ad_unit_id );

   if ( admobAdUnitId != null && !admobAdUnitId.equals( ( "" ) ) ) {
      mAdView = new AdView( this );
      mAdView.setAdSize( AdSize.BANNER );
      mAdView.setAdUnitId( admobAdUnitId );

      mAdFrame.addView( mAdView );

      String[] testDeviceIds = getResources().getStringArray( R.array.admob_test_device_ids );

      AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
      adRequestBuilder.addTestDevice( AdRequest.DEVICE_ID_EMULATOR );

      for ( int i = 0; i < testDeviceIds.length; i++ ) {
         adRequestBuilder.addTestDevice( testDeviceIds[i] );
      }

      AdRequest adRequest = adRequestBuilder.build();
      mAdView.loadAd( adRequest );
   }
}
 
開發者ID:hoolrory,項目名稱:VideoInfoViewer,代碼行數:24,代碼來源:MainActivity.java

示例11: setupAds

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void setupAds() {
   String admobAdUnitId = getString( R.string.video_activity_admob_ad_unit_id );

   if ( admobAdUnitId != null && !admobAdUnitId.equals( ( "" ) ) ) {
      mAdView = new AdView( this );
      mAdView.setAdSize( AdSize.BANNER );
      mAdView.setAdUnitId( admobAdUnitId );

      mAdFrame.addView( mAdView );

      String[] testDeviceIds = getResources().getStringArray( R.array.admob_test_device_ids );

      AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
      adRequestBuilder.addTestDevice( AdRequest.DEVICE_ID_EMULATOR );

      for ( int i = 0; i < testDeviceIds.length; i++ ) {
         adRequestBuilder.addTestDevice( testDeviceIds[i] );
      }

      AdRequest adRequest = adRequestBuilder.build();
      mAdView.loadAd( adRequest );
   }
}
 
開發者ID:hoolrory,項目名稱:VideoInfoViewer,代碼行數:24,代碼來源:VideoActivity.java

示例12: AdDialogHelper

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
/**
 * Constructor
 * 
 * @param activity
 * @param fragmentTag
 */
public AdDialogHelper(FragmentActivity activity, String fragmentTag) {
    mActivity = activity;
    mFragmentTag = fragmentTag;

    mAdDialogFragment = new AdDialogFragment();
    mAdDialogFragment.setCancelable(false);

    // Create the adView
    mAdView = new AdView(activity);
    mAdView.setAdUnitId(activity.getString(R.string.admob_in_game_ad_unit));
    mAdView.setAdSize(AdSize.BANNER);
    mAdView.setAdListener(this);

    if (AdsHelper.shoulShowAds(activity)) {
        AdsHelper.requestAd(mAdView);
    }
}
 
開發者ID:sergiotorresperez,項目名稱:jumplings,代碼行數:24,代碼來源:AdDialogHelper.java

示例13: createLayoutWithAd

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
public static LinearLayout createLayoutWithAd(Activity activity) {
      LinearLayout layout = new LinearLayout(activity);
      layout.setOrientation(LinearLayout.VERTICAL);
      
      LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
      lp.gravity = Gravity.CENTER_HORIZONTAL;
      AdView goodAdv = new AdView(activity); //, com.google.ads.AdSize.BANNER, GOOGLE_AD_ID
      if (LiveWallpaperSettings.DEBUG) {
      	goodAdv.setAdUnitId("");
} else {
	goodAdv.setAdUnitId("ca-app-pub-7879767097814866/4363554030");
}
      goodAdv.setAdSize(AdSize.BANNER);
      layout.addView(goodAdv);
      AdRequest.Builder builder = new Builder();
      goodAdv.loadAd(builder.build());
      return layout;
  }
 
開發者ID:GggXp,項目名稱:AndroidLiveWallpaper,代碼行數:19,代碼來源:GoogleAdmob.java

示例14: trySetupAdView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
protected void trySetupAdView(){

        mAdViewContainer = (LinearLayout) findViewById(R.id.admob_container);

        if(mAdViewContainer != null){
            mAdView = new AdView(this);
            mAdView.setAdUnitId(BuildConfig.AD_UNIT_ID);
            mAdView.setAdSize(AdSize.BANNER);
            mAdViewContainer.addView(mAdView);

            AdRequest.Builder builder = new AdRequest.Builder();
            if(BuildConfig.DEBUG){
                builder.addTestDevice(BuildConfig.AD_TEST_DEVICE_ID);
            }
            AdRequest adRequest = builder.build();
            mAdView.loadAd(adRequest);
        }
    }
 
開發者ID:gbaldera,項目名稱:Yts,代碼行數:19,代碼來源:BaseActivity.java

示例15: requestAd

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
/**
 * Interface called by the AN SDK to request an ad from the mediating SDK.
 *
 * @param mBC                 the object which will be called with events from the 3rd party SDK
 * @param activity            the activity from which this is launched
 * @param parameter           String parameter received from the server for instantiation of this object
 * @param adUnitID            The 3rd party placement , in adMob this is the adUnitID
 * @param width               Width of ad
 * @param height              Height of ad
 * @param targetingParameters targetingParameters
 */
@Override
public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter,
                      String adUnitID, int width, int height, TargetingParameters targetingParameters) {
    adListener = new GooglePlayAdListener(mBC, super.getClass().getSimpleName());
    adListener.printToClog(String.format(" - requesting an ad: [%s, %s, %dx%d]",
            parameter, adUnitID, width, height));

    adView = new AdView(activity);
    adView.setAdUnitId(adUnitID);
    adView.setAdSize(new AdSize(width, height));
    adView.setAdListener(adListener);

    try {
        adView.loadAd(buildRequest(targetingParameters));
    } catch (NoClassDefFoundError e) {
        // This can be thrown by Play Services on Honeycomb.
        adListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NO_FILL);
    }

    return adView;
}
 
開發者ID:appnexus,項目名稱:mobile-sdk-android,代碼行數:33,代碼來源:GooglePlayServicesBanner.java


注:本文中的com.google.android.gms.ads.AdView.setAdSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。