我正在尝试更改我的 AdView
在 SherlockFragmentActivity(带有标签)中的位置。由于现在 AdView
显示在屏幕底部,我想更改 AdView
的位置,使其显示在 ActionBar< 之间
选项卡和 fragment 布局。
这是我在屏幕底部放置广告的布局(效果很好):
<?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="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/admod_id" />
</LinearLayout>
这是我试图改变它的方式:
<?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="match_parent"
android:orientation="vertical" >
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/admod_id" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
</LinearLayout>
此更改会在 onCreate()
方法的以下代码行中导致 ClassCastExeption
。
adView = (AdView) findViewById(R.id.adview);
出现此错误消息:
Caused by: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to com.google.ads.AdView
如果有人能解释为什么这会导致 ClassCastException
以及我将如何解决这个问题,那就太好了。
最佳答案
尝试在更改位置后清理项目。
关于java - 更改 AdView 位置时出现 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620685/