Layout Problem

I'm developing an App with Android Studio and I included ads. For this I made a frame layout and added an ad banner below. In the emulator everything works as intended at I'm able to display test ads. However, when I'm running it on the phone the frame with the processing sketch fills up the whole screen. I don't get why it works on the emulator (I tried different Android versions.), but not on the real device.

logcat does not mention any ad related errors, just "Ad finished loading." Here is the layout xml file (without my app unit id).

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:name=".rhythm_soundpool_final_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    <FrameLayout android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_above="@+id/adView">
    </FrameLayout>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxxxx/xxxxxxxxxxx"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

And here is the part of MainActivity, that actually matters for the ads.

public class MainActivity extends Activity {
    PApplet fragment;
    private static final String MAIN_FRAGMENT_TAG = "main_fragment";
    private static final int REQUEST_PERMISSIONS = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        if (savedInstanceState == null) {
          fragment = new rhythm_soundpool_final_2();
          FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.container, fragment).commit();
            } else {
            fragment = (PApplet) getFragmentManager().findFragmentByTag(MAIN_FRAGMENT_TAG);
        }

       MobileAds.initialize(getApplicationContext(), "ca-app-pub-4464966848174171~2518304649");
       AdView mAdView = (AdView) findViewById(R.id.adView);
       //AdRequest request = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
       AdRequest request = new AdRequest.Builder().addTestDevice("8258EDD0C06FE07322AE476AAD7S83A7").build();

       mAdView.loadAd(request);
    }

}

Answers

  • Answer ✓

    Ok, never mind. Problem solved. It seems, that the problem is connected to my specific type of phone (Huawei P8). I'm not the only one with this issue. However, it works on other phones.

Sign In or Register to comment.