2015-07-04 77 views
1

我有一個片段佈局xml,其中RelativeLayout包含AdView,屬性android:layout_alignParentBottom="true"但它沒有在底部對齊。layout_alignParentBottom不能在RelativeLayout中工作

我也有這個代碼工作的另一個佈局xml。請看下面的兩個文件。

fragment_info:(這裏AdView不被對齊底部)

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

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/refreshIndicator" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <WebView 
      android:id="@+id/blogInfoWebView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adViewBlogInfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/blog_info_ad_unit" /> 

</RelativeLayout> 

fragment_search:(這裏AdView獲得對準底部)

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <!-- Some code --> 

    </LinearLayout> 

    <include layout="@layout/fragment_post_list_web_view" /> 

</LinearLayout> 

<com.google.android.gms.ads.AdView 
    android:id="@+id/adViewSearchList" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentBottom="true" 
    ads:adSize="BANNER" 
    ads:adUnitId="@string/search_list_ad_unit" /> 

</RelativeLayout> 
+0

爲webview提供完整的高度屬性:'android:layout_heig HT = 「match_parent」' – NamNH

回答

0

看看這個線性佈局

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:layout_height="match_parent"> 

     <android.support.v4.widget.SwipeRefreshLayout 
      android:id="@+id/refreshIndicator" 
      android:layout_weight="1" 
      android:layout_width="match_parent" 
      android:layout_height="0dp"> 

      <WebView 
       android:id="@+id/blogInfoWebView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

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

     <com.google.android.gms.ads.AdView 
      android:id="@+id/adViewBlogInfo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      ads:adSize="BANNER" 
      ads:adUnitId="@string/blog_info_ad_unit" /> 

    </LinearLayout> 
相關問題