我是一名相对新手的安卓应用程序员,尝试在应用中实现广告。我正在像下面这样在片段中添加一个横幅广告:
<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中,但是我会收到一个错误,说没有足够的空间来容纳广告(广告大小为320x50,可用空间为0x600,类似于此)。我尝试让Java代码成为片段中运行的第一件事,但然后它立即跳转到AdView,并在几秒钟后仍然跳转。我最好的猜测是我必须覆盖AdView中的某个类?