2017-04-18 44 views
0

如何将AdView(AdMob)广告推送到Android Activity的页面底部?这里是我的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