为什么 Android 视图跳转到 Admob 广告?
Why is Android View jumping to Admob ad?
我是一个相当新的 Android 应用程序程序员,正在尝试在应用程序中植入广告。我在这样的片段中加入了横幅广告
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/meScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mePageRelLayout">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="@+id/chart">
</com.google.android.gms.ads.AdView>
lots and lots of
<TextView
.../>
<TextView
.../>
<ImageView
android:id="@+id/chart"
.../>
</RelativeLayout>
</ScrollView>
和Java像这样:
AdView mAdView = (AdView) rootView.findViewById(R.id.adView2);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
每当我进入那个片段时,视图开始时都很好。我在顶部看到了我想要的 TextView 和 ImageView。然后,视图跳转到 AdView,我一直将它放在 ScrollView 的底部。我不希望它跳转到 AdView。每当我滚动离开时,这种情况每隔几秒钟就会发生一次。为什么会发生这种情况,我该如何解决?
我试过将它放在 RelativeLayout 的其他位置,但它仍然跳转到它所在的位置。我已经将它从 RelativeLayout 中取出并放在 ScrollView 中,但随后我收到一条错误消息,指出广告没有任何 space(广告为 320x50,可用 space 为 0x600 , 或类似的东西)。我试过让 Java 代码成为片段中运行的第一件事,但它立即跳转到 AdView,并且之后仍然每隔几秒跳一次。我最好的猜测是我必须覆盖 AdView 中的一些 class?
我认为您需要向 ScrollView 添加其他内容。如果已经有其他内容,请尝试在滚动视图中的所有其他内容之前以编程方式实例化广告。如果你想让广告和ScrollView分开,把它放在外面但是在同一个fragment中。
当 adView 接收内容时,它可能会导致自身短暂地获得焦点,或者导致包含的 ScrollView 重新定位以显示 AdView。
我强烈建议将 AdView 移到 ScrollView 之外,因为这会
- 回避问题。
- 确保 AdView 始终显示,从而增加您的收入。
我是一个相当新的 Android 应用程序程序员,正在尝试在应用程序中植入广告。我在这样的片段中加入了横幅广告
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/meScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mePageRelLayout">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="@+id/chart">
</com.google.android.gms.ads.AdView>
lots and lots of
<TextView
.../>
<TextView
.../>
<ImageView
android:id="@+id/chart"
.../>
</RelativeLayout>
</ScrollView>
和Java像这样:
AdView mAdView = (AdView) rootView.findViewById(R.id.adView2); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest);
每当我进入那个片段时,视图开始时都很好。我在顶部看到了我想要的 TextView 和 ImageView。然后,视图跳转到 AdView,我一直将它放在 ScrollView 的底部。我不希望它跳转到 AdView。每当我滚动离开时,这种情况每隔几秒钟就会发生一次。为什么会发生这种情况,我该如何解决?
我试过将它放在 RelativeLayout 的其他位置,但它仍然跳转到它所在的位置。我已经将它从 RelativeLayout 中取出并放在 ScrollView 中,但随后我收到一条错误消息,指出广告没有任何 space(广告为 320x50,可用 space 为 0x600 , 或类似的东西)。我试过让 Java 代码成为片段中运行的第一件事,但它立即跳转到 AdView,并且之后仍然每隔几秒跳一次。我最好的猜测是我必须覆盖 AdView 中的一些 class?
我认为您需要向 ScrollView 添加其他内容。如果已经有其他内容,请尝试在滚动视图中的所有其他内容之前以编程方式实例化广告。如果你想让广告和ScrollView分开,把它放在外面但是在同一个fragment中。
当 adView 接收内容时,它可能会导致自身短暂地获得焦点,或者导致包含的 ScrollView 重新定位以显示 AdView。
我强烈建议将 AdView 移到 ScrollView 之外,因为这会
- 回避问题。
- 确保 AdView 始终显示,从而增加您的收入。