本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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 );
}
}
示例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 );
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}