APP

[Android Studio] 웹뷰 애드몹 광고 하단배치 #웹뷰어플 #Webview

TaeHuiLee 2022. 6. 8. 04:44
반응형

 

애드몹 광고를 적용하고 나서 배치를 바꾸려고 하면 잘 되지 않는 문제가 발생한다.

광고를 원하는 위치에 다양하게 배치시키는 방법을 설명하겠다.

 

 

APP에 애드몹 광고 적용하는 방법은 아래의 포스팅 참고

2022.06.06 - [APP] - [Android Studio] 어플에 광고(배너) 넣기 #웹뷰어플 #Webview

 

 

기존에 상단 배너 배치 xml

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" >
        </WebView>
        </FrameLayout>
        
        <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"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            app:adSize="BANNER"
            app:adUnitId="ca-app-pub-3940256099942544/6300978111">

        </com.google.android.gms.ads.AdView>
    </FrameLayout>

</LinearLayout>

 

 

하단 배너 배치 xml

android:layout_gravity="bottom" 추가

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" >
        </WebView>
        </FrameLayout>

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            
            android:layout_gravity="bottom"
            
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            app:adSize="BANNER"
            app:adUnitId="ca-app-pub-3940256099942544/6300978111">

        </com.google.android.gms.ads.AdView>
    </FrameLayout>

</LinearLayout>

 

이런식으로 android:layout_gravity = '원하는 위치'를 해주면 마음대로 배너의 위치를 바꿀 수 있다.

 

반응형