2017-03-07 25 views
0

我的AdView放置在RelativeLayout的底部,但是我的RelativeLayout正在關閉屏幕,使得我的AdView不可見。我如何解決這個問題?RelativeLayout內部的AdView正在關閉屏幕

編輯:此XML包含摺疊工具欄佈局。

XML:

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
    ... 
    </android.support.design.widget.AppBarLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerview_category_details" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical"/> 

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

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

    </RelativeLayout> 

</android.support.design.widget.CoordinatorLayout> 
+0

你可以發佈你的XML文件嗎? –

+0

@AngeloParente新增 – RandomyzeEverything

+0

我已經添加了答案。看看它是否有幫助。這是一個代碼示例。 –

回答

0

嘗試類似的東西。

您應該使用RelativeLayout父佈局,把AD瀏覽在它的底部,並指定android:layout_above="@+id/adView"財產,這是一個示例代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MainActivity"> 

     <android.support.design.widget.CoordinatorLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/main_content" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/adView"> 

      <android.support.design.widget.AppBarLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/main_button_background"> 

      </android.support.design.widget.AppBarLayout> 

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

       <android.support.v7.widget.RecyclerView 
        android:id="@+id/recyclerview_category_details" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:scrollbars="vertical"/> 

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

     </android.support.design.widget.CoordinatorLayout> 

     <com.google.android.gms.ads.AdView 
      android:id="@id/adView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      ads:adSize="BANNER" 
      ads:adUnitId="@string/banner_ad_unit_id" 
      android:layout_gravity="center|bottom" 
      android:layout_alignParentBottom="true"/> 

    </RelativeLayout> 

讓我知道,如果它幫助。

+0

謝謝。這工作! – RandomyzeEverything

+0

歡迎您:) –

0

刪除佈局adview,並把他們都在另一RelativeLayout,並設置屬性爲android:above="@id/adview"RelativeLayout

+0

這不起作用。我現在在帖子中添加了我的xml。 – RandomyzeEverything