2017-09-13 7 views
-1

탐색 창을 사용하여 프로젝트에 admob 광고를 추가했습니다. 나는 admob 광고를 서랍 뒤에 밀어 넣고 싶다. 다음 xml 코드를 사용했지만 완벽하게 작동하지 않습니다.탐색 창 뒤에서 admob 광고를 푸시하는 방법은 무엇입니까?

<?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> 

첨부 된 그림을 참조하십시오. Example of problem

+0

이 줄을 추가하십시오. 'android : layout_alignParentBottom = "true"'당신의 서랍 레이아웃 –

답변

0

여기가 해결책입니다.
당신은이 파일로 AdView를 제거하고 단지
당신의 app_bar_main 레이아웃에서 해당 파일을

여기

<?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> 

여기
activity_main.xml입니다 UPDATE 추가 필요 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

답장을 보내 주셔서 감사합니다. 예제 코드가 있습니까? – Bishwash

+0

예 업데이트를 참조하십시오. –

+0

올바르게 작동하지 않습니다. 파편의 내용과 겹칩니다. 나는 adview가 조각을 넘어 여분의 공간을 필요로하고 싶다. – Bishwash