Android &引用;Can';t在第一次布局后获取viewWidth“;错误
我不能用我的生命来弥补这个错误。我看过谷歌和其他公司,但没有一个有效的解决方案。我的广告似乎在安卓1.5和1.6上运行良好,但在2版以上的版本中,我就犯了这个错误 我把我的广告放在一个线性布局中,这是滚动视图中的第一个布局Android &引用;Can';t在第一次布局后获取viewWidth“;错误,android,xml,admob,Android,Xml,Admob,我不能用我的生命来弥补这个错误。我看过谷歌和其他公司,但没有一个有效的解决方案。我的广告似乎在安卓1.5和1.6上运行良好,但在2版以上的版本中,我就犯了这个错误 我把我的广告放在一个线性布局中,这是滚动视图中的第一个布局 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:background="@drawable/bg_wallpaper"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:id="@+id/drillactivity"
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:layout_height="340dp">
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="my id goes here"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
我没有在我的类中为广告使用任何代码。我更喜欢只通过xml来做 我有类似的黑屏警告。问题是设备上有两个不同的应用程序具有相同的AdMob id
我删除了第二个应用程序(错误地使用了相同的id)和问题提示。使用以下代码,我修复了此错误
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="320dp"
android:layout_height="50dp"
android:gravity="center"
ads:adUnitId="my id goes here"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
我没有得到这个错误的任何具体原因,它可能不适用于所有情况。在xml中声明一个线性/相对布局,您将在您的活动中使用它。然后将活动作为侦听器设置为adView。 比如:
这里adMobLayout是您在xml布局中声明的布局。loadAdOnCreate做什么?在我的例子中,它导致了以下警告:“loadAd在ad已加载时调用,因此正在中止。”loadAdOnCreate将在onCreate中加载ad。因此,您不必在onCreate中单独发送广告请求。
googleAdView = new AdView(Activity,AdSize.IAB_BANNER, ADMOB_SITE_ID);
googleAdView.setAdListener(Activity);
com.google.ads.AdRequest request = new com.google.ads.AdRequest();
this.adMobLayout.removeAllViews();
this.adMobLayout.addView(googleAdView);
googleAdView.loadAd(request);