I'm a fairly new Android app programmer trying to implement ads in an app. I'm including a Banner ad in a fragment like so
<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>
And Java like so:
AdView mAdView = (AdView) rootView.findViewById(R.id.adView2); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest);
Whenever I go into that fragment, the view starts out fine. I see the TextView and ImageView that I want at the top. Then, the view jumps to the AdView, which I've placed all the way at the bottom of the ScrollView. I'd like it to not jump to the AdView. This happens every few seconds, whenever I scroll away. Why does this happen, and what can I do to fix it?
I've tried placing it other places within the RelativeLayout but it still jumps to wherever it is. I've taken it out of the RelativeLayout and just put it in the ScrollView but then I get an error saying that there isn't any space for the ad (Ad is 320x50, Available space is 0x600, or something like that). I've tried making the Java code the first thing that runs in the fragment, but then it immediately jumps to the AdView and still jumps every few seconds afterwards. My best guess is I have to override some class in AdView?
It is likely that as the adView receives content is it causing itself to briefly receive focus or otherwise cause the containing ScrollView to reposition to show the AdView.
I would strongly recommend moving the AdView outside of the ScrollView as this will