2016-09-08 5 views
0

私は主な活動からFragmentsに切り替わります。現時点では、それぞれFragmentから新しいAdViewを呼び出していますが、私はAdViewFragmentsのすべてに見られるメインアクティビティから呼び出すだけです。Adview以下FrameLayout

ここでAdViewFrameLayoutの中に表示しないようにする方法を知る必要があります。なぜなら、コンテンツが下部でブロックされているからです。

FrameLayoutのコンテンツの外/下にあるAdViewを入手するにはどうすればよいですか?

content_main.xml

<RelativeLayout 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" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context=".activity.MainActivity" 
tools:showIn="@layout/app_bar_main"> 


<FrameLayout 
    android:id="@+id/mainFrame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

</FrameLayout> 

<RelativeLayout 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/mainFrame"> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="15dp" 
     android:layout_gravity="center" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/banner_ad_unit_id"> 
    </com.google.android.gms.ads.AdView> 

</RelativeLayout> 

</RelativeLayout> 
+0

:サブ'RelativeLayout'に' layout_weight = "1" を。 – doubotis

+0

下記の私の答えをチェックし、問題が発生した場合は教えてください。 –

答えて

3

のみを使用して、単一のRelative LayoutRoot Layoutとして、その後Frame Layoutandroid:layout_above="@+id/adView"を使用しています。

ここはxmlコードです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/frameLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/adView" 
     android:background="@mipmap/ic_launcher" /> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" /> 

</RelativeLayout> 

​​3210

その後、 `アンドロイド追加、LinearLayout``へあなたのトップ `RelativeLayout`を変更
+1

ありがとう! –