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


Java AdView.setLayoutParams方法代碼示例

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


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

示例4: 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

示例5: 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

示例6: onCreateView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    
	//Create the AdView fragment container layout
    View v = inflater.inflate(R.layout.fragment_ad, container, false);
    
    //Generate the AdView and configure it
    mAdView = new AdView(v.getContext());
    mAdView.setVisibility(View.GONE);
    RelativeLayout.LayoutParams mAdViewLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mAdView.setLayoutParams(mAdViewLayout);
    //...set the Ads info
    mAdView.setAdSize(adSize);
    mAdView.setAdUnitId(adUnitId);
    
    //Add the AdView to the fragment container layout :)
    ((RelativeLayout)v).addView(mAdView);
    
    return v;
}
 
開發者ID:javocsoft,項目名稱:javocsoft-toolbox,代碼行數:22,代碼來源:AdFragment.java

示例7: createadmob

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private AdView createadmob() {
    AdView mAdView = new AdView(this);
    mAdView.setAdSize(AdSize.MEDIUM_RECTANGLE);
    mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    mAdView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    // Create an ad request.
    AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
    if (admob_test_mode)
        // Optionally populate the ad request builder.
        adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
    // Start loading the ad.
    mAdView.loadAd(adRequestBuilder.build());
    return mAdView;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:TestAdMobClassicActivity.java

示例8: createAdView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private void createAdView() {
    adView = new AdView(this);
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId(AD_UNIT_ID);
    adView.setId(R.id.adsMobId); // this is an arbitrary id, allows for relative positioning in createGameView()
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    adView.setLayoutParams(params);
    adView.setBackgroundColor(Color.BLACK);
}
 
開發者ID:ZephyrVentum,項目名稱:FlappySpinner,代碼行數:12,代碼來源:AndroidLauncher.java

示例9: createAdView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private AdView createAdView() {
  adView = new AdView(this);
  adView.setAdSize(AdSize.SMART_BANNER);
  adView.setAdUnitId(AD_UNIT_ID);
  adView.setId(12345); // this is an arbitrary id, allows for relative positioning in createGameView()
  RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
  params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
  adView.setLayoutParams(params);
  adView.setBackgroundColor(Color.BLACK);
  return adView;
}
 
開發者ID:Jocke101,項目名稱:MathMemory,代碼行數:13,代碼來源:AndroidLauncher.java

示例10: createAdView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private AdView createAdView() {
    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId(getString(R.string.ad_banner1));
    adView.setId(12345);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    adView.setLayoutParams(params);
    adView.setBackgroundColor(Color.BLACK);
    return adView;
}
 
開發者ID:mcprog,項目名稱:ragnar,代碼行數:13,代碼來源:AndroidLauncher.java

示例11: createAdView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
private AdView createAdView() {
	adView = new AdView(this);
       adView.setAdSize(AdSize.SMART_BANNER);
       adView.setAdUnitId(SMALL_CODE);
       adView.setId(12345); // this is an arbitrary id, allows for relative positioning in createGameView()
       RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
       params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
       params.addRule(RelativeLayout.CENTER_HORIZONTAL);
       layout.setLayoutParams(params);
       adView.setLayoutParams(params);
       adView.setBackgroundColor(Color.TRANSPARENT);
       return adView;
}
 
開發者ID:costular,項目名稱:crabox,代碼行數:14,代碼來源:AndroidLauncher.java

示例12: getView

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if ((position % 5) == 2) {
        if (convertView instanceof AdView) {
            // Don’t instantiate new AdView, reuse old one
            return convertView;
        } else {
            // Create a new AdView
            AdView adView = new AdView(activity);
            adView.setAdUnitId(activity.getResources().getString(R.string.banner_ad_unit_id_test));
            adView.setAdSize(AdSize.BANNER);
            adView.loadAd(createAdRequest());
            adView.setAdListener(new LogAndToastAdListener(activity));

            // Convert the default layout parameters so that they play nice with
            // ListView.

            float density = activity.getResources().getDisplayMetrics().density;
            int height = Math.round(AdSize.BANNER.getHeight() * density);
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(
                    AbsListView.LayoutParams.MATCH_PARENT,
                    height);

            adView.setLayoutParams(params);
            return adView;
        }
    } else {
        if (convertView instanceof AdView) {
            convertView = null;
        }
        // Offload displaying other items to the delegate
        return delegate.getView(position - ((position + 3) / 5),
                convertView, parent);
    }
}
 
開發者ID:pgodzin,項目名稱:QuotesSocial,代碼行數:36,代碼來源:AdListAdapter.java

示例13: onCreate

import com.google.android.gms.ads.AdView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main_page);
	
	
	adView = new AdView(this);
	adView.setAdUnitId("ca-app-pub-4147454460675251/3837655321");
	adView.setAdSize(AdSize.BANNER);
	
	adView.setAdListener(adListener);
	
	RelativeLayout adLayout = (RelativeLayout)findViewById(R.id.main_page_adview_layout);
	adLayout.addView(adView);
	
	RelativeLayout.LayoutParams adViewlp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	adViewlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
	adViewlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
	adView.setLayoutParams(adViewlp);

	
	AdRequest request = new AdRequest.Builder()
	.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("04E14595EE84A505616E50A99B15252D")
    .build();
	
	
	adView.loadAd(request);
	
	System.out.println("---------------------- istestdevice: "+request.isTestDevice(this));

	
	mContext = this;
	
	DisplayMetrics dm = new DisplayMetrics();
	getWindowManager().getDefaultDisplay().getMetrics( dm );
	
	screenWidth = dm.widthPixels;
	screenHeight = dm.heightPixels;
	
	final TextView headerText = (TextView)findViewById(R.id.mainHeaderText);
	RelativeLayout.LayoutParams headerTextParams = (RelativeLayout.LayoutParams)headerText.getLayoutParams();
	headerTextParams.leftMargin = screenHeight/8;
	headerText.setLayoutParams(headerTextParams);
	headerText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, (float)screenHeight/35);
	headerText.setText("Face Recognition");
	headerText.setTextColor(Color.LTGRAY);
	headerText.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
	headerText.setTypeface(null, Typeface.BOLD);
	
	ImageView headerIcon = (ImageView)findViewById(R.id.mainHeaderIcon);
	RelativeLayout.LayoutParams iconLParams = new RelativeLayout.LayoutParams(screenHeight/11, screenHeight/11);
	iconLParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT | RelativeLayout.CENTER_VERTICAL);
	iconLParams.leftMargin = screenHeight/80;
	headerIcon.setLayoutParams(iconLParams);
	
	
	ListView listView = (ListView)findViewById(R.id.mainListView);
	ListAdapter listAdapter = new ListAdapter();
	listView.setAdapter(listAdapter);
	listView.setOnItemClickListener(itemClickListener);
	
	RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)listView.getLayoutParams();
	params.leftMargin = screenWidth/10;
	params.rightMargin = screenWidth/10;
	params.topMargin = screenHeight/12;
	listView.setLayoutParams(params);
	listView.setVerticalScrollBarEnabled(false);

}
 
開發者ID:yaylas,項目名稱:AndroidFaceRecognizer,代碼行數:71,代碼來源:MainPageActivity.java


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