Android-如何动态设置AdMob广告商ID或广告大小?
在xml文件中使用给定的广告客户ID和广告大小,中提供的示例代码对我来说效果很好。但对我来说,能够根据某些参数设置广告客户ID和横幅大小是非常重要的 我考虑过这两个,但它们不适合我-> 及Android-如何动态设置AdMob广告商ID或广告大小?,android,admob,Android,Admob,在xml文件中使用给定的广告客户ID和广告大小,中提供的示例代码对我来说效果很好。但对我来说,能够根据某些参数设置广告客户ID和横幅大小是非常重要的 我考虑过这两个,但它们不适合我-> 及 当我尝试实现第二个时,当我尝试将java文件链接到xml文件时会出现错误。它们应该如何链接?请发布您的代码@阿里波瓦拉 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.a
当我尝试实现第二个时,当我尝试将java文件链接到xml文件时会出现错误。它们应该如何链接?请发布您的代码@阿里波瓦拉
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/adView"
android:layout_width="match_parent"
android:background="@null"
android:layout_height="wrap_content" />
</LinearLayout>
AdView mAdView = new AdView(context);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId(AD_UNIT_ID);
FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.adView);
frameLayout.addView(mAdView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);