I were using AdMob from Google Play services version 13. I realize, when I place the advertisement within ScrollView
, AdMob will try to perform undesired auto scrolling, after it fetches the advertisement successfully from server.
package com.example.admob_bug;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the adView.
adView = new AdView(this);
adView.setAdUnitId("a151b03485063e0");
adView.setAdSize(AdSize.BANNER);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout".
LinearLayout layout = (LinearLayout)findViewById(R.id.advertisement);
// Add the adView to it.
layout.addView(adView);
// Initiate a generic request.
AdRequest adRequest = new AdRequest.Builder().build();
// Load the adView with the ad request.
adView.loadAd(adRequest);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onPause() {
adView.pause();
super.onPause();
}
@Override
public void onResume() {
super.onResume();
adView.resume();
}
@Override
public void onDestroy() {
adView.destroy();
super.onDestroy();
}
private AdView adView;
}
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
...
...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text 7"
android:layout_margin="30dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/advertisement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text 8"
android:layout_margin="30dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</ScrollView>
The complete source code can be downloaded from https://www.dropbox.com/s/e53zjqsc5cnilz2/admob_bug.zip
You will realize this problem, after you wait for around 10 seconds (Depending on network quality), after advertisement is loaded.
Is there any workaround to prevent auto scrolling?
This problem wasn't there, before I switch from old AdMob 6.4.1 JAR, to AdMob of Google Play Service.
I'm testing using device Nexus S, Android 4.1.2.
update your activity_main.xml
<LinearLayout
android:id="@+id/advertisement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
</LinearLayout>
it is working fine. testing with nexus 4 and samsung galaxy s.also emulator api 18.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With