2017-09-13 2 views
-1

Ich habe Admob Ads auf dem Projekt mit Navigationsleiste hinzugefügt. Ich möchte, dass die Admob-Anzeigen hinter die Schublade geschoben werden. Ich habe folgenden XML-Code verwendet, aber es funktioniert nicht perfekt.Wie pushen Admob-Anzeigen hinter der Navigationsleiste?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:gravity="center" 
android:layout_alignParentBottom="true" 
android:id="@+id/bannerAdLayout"> 
<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="ca-app-pub-xxx/yyy" 
    /> 

</LinearLayout> 
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_above="@+id/bannerAdLayout" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:itemIconTint="#000000" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 

Siehe das beigefügte Bild. Example of problem

+0

fügen Sie diese Zeile 'android: layout_alignParentBottom =" true "' in Ihrem Schubladenlayout hinzu –

Antwort

0

Hier ist Ihre Lösung.
müssen Sie adView aus dieser Datei entfernen und fügen Sie einfach die Datei in
Ihr app_bar_main Layout

UPDATE
hier ist mein activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout  
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:openDrawer="start"> 
<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 
<android.support.design.widget.NavigationView 

    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:layout_marginTop="?actionBarSize" 
    android:background="@drawable/bg" 
    app:itemTextAppearance="@style/NavigationDrawerStyle" 
    app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

hier ist mein app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 

android:id="@+id/realative" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

xmlns:app="http://schemas.android.com/apk/res-auto" 
> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/appBarLayout" 
    > 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     > 
    </android.support.v7.widget.Toolbar> 

</android.support.design.widget.AppBarLayout> 
<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="ca-app-pub-xxx/yyy" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

</RelativeLayout> 
+0

Vielen Dank für die Antwort. Hast du einen Beispielcode? – Bishwash

+0

ja, siehe mein UPDATE –

+0

Das funktioniert nicht richtig. Es überlappt den Inhalt der Fragmente. Ich möchte, dass die Adview zusätzlichen Platz außerhalb des Fragments benötigt. – Bishwash

Verwandte Themen