2017-04-18 6 views
0

Android 활동의 페이지 하단에 AdView (AdMob) 광고를 삽입하려면 어떻게해야하나요? 여기 내 activity_main.xml 레이아웃 코드가 있습니다. 웬일인지 그것이 바닥에 정렬하지 않는다. 내부에서 AdView를 작동시키지 못했습니다. 어떤 도움을 주셔서 감사합니다.Android 앱에서 AdView를 페이지 하단에 밀어 넣는 방법

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/linearLayout_main" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    tools:context=".MainActivity"> 

    <!--custome toolbar--> 
    <include layout="@layout/tool_bar" /> 

    <!--Wifi name and state--> 
    <LinearLayout 
     android:id="@+id/linear_wifi_name" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/wifi_icon_id" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.20" /> 

     <TextView 
      android:id="@+id/wifi_name" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.60" 
      android:textSize="20dp" 
      android:gravity="center" 
      android:textAlignment="center" /> 

     <ImageView 
      android:id="@+id/scan_icon" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.20" 
      android:src="@drawable/ic_keyboard_arrow_right_white_36dp"/> 

    </LinearLayout> 

    <!--Progess bar--> 
    <ProgressBar 
     style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="visible" 
     android:id="@+id/progress_bar" /> 

    <!--this section is for wifi/private network--> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="5dp"> 

     <TextView 
      android:id="@+id/result_local" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:typeface="monospace" 
      android:text="Local Network:" 
      android:textColor="@color/colorAccent" 
      android:textSize="20dp"/> 

     <TextView 
      android:id="@+id/private_net_info" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:typeface="monospace" 
      android:textSize="16dp"/> 

    </LinearLayout> 

    <!--this section is for public ip info--> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="5dp"> 

     <TextView 
      android:id="@+id/result_public" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:typeface="monospace" 
      android:textColor="@color/colorAccent" 
      android:text="Public Ip:" 
      android:textSize="20dp"/> 

     <TextView 
      android:id="@+id/public_net_info" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:typeface="monospace" 
      android:textSize="16dp"/> 

    </LinearLayout> 

    <!-- banner ads for AdsMob--> 
    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView_main" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     ads:adSize="BANNER" 
     ads:adUnitId="ca-app-pub-3940256099942544/6300978111" 
     android:padding="5dp"> 
    </com.google.android.gms.ads.AdView> 

</LinearLayout> 

답변

1

다른보기 중 하나는 나머지 공간을 채워야 광고가 하단으로 밀려납니다. 당신은 AdView가 위에서이 권리를 추가하여 해당 작업을 수행 할 수 있습니다

<!-- fill remaining space --> 
<Space 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_weight="1" /> 

이 또한주의 : 무게가 1까지 추가 할 필요가 없습니다 그것은 다른 아이들 만 상대입니다. 따라서 레이아웃에서 가중치 0.2, 0.6 및 0.2를 사용한 경우 동일한 효과에 대해 1, 3 및 1을 사용할 수도 있습니다.
하나의 하위에만 가중치가 있으면 값에 관계없이 나머지 모든 공간을 소비합니다.

+0

감사합니다 ... 많이! – miatech