【发布时间】:2023-03-23 07:35:01
【问题描述】:
我使用了 admob sdk 并添加为外部 jar。在我指定的 xml 中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/headerfield"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="Publisher Id"
ads:loadAdOnCreate="true" />
</LinearLayout>
清单
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
但在图形模式下,它会给我一个错误日志:
com.google.ads.AdView - the following class could not be instantiated.
在程序内部显示
您必须在 AndroidManifest.xml 中使用 configChanges 声明 AdActivity。
【问题讨论】:
-
<?xml version="1.0" encoding="utf-8"?><br/><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/bgshare"> -
<ListView android:id="@+id/list"android:layout_width="fill_parent"android:layout_height="wrap_content">然后这是问题内指定的广告视图,然后关闭相对布局 -
看起来很奇怪 - 您的 AdView 在 ListView 中吗?正如 becomputer 建议的那样,在您的问题中发布整个布局文件。
-
我的布局在我调用 adView 的程序中运行良好,它显示的 AdActivity 应该在 AndroidManifest 中声明 configChanges,即使我已经编写了 configChanges