我已经为我的应用实施了横幅广告。加载广告后,回收站视图会停留在上方,并且不会与之重叠,也不会与回收站视图重叠。但是,当未加载广告时,仍然存在尺寸与横幅相同的白色“补丁”。我想要的是,如果未加载广告,则该补丁不应存在于版面中;如果加载了广告,请创建类似的补丁,并且不要覆盖回收站视图内容。我知道有一个框架布局可以重叠不同的视图,但是据我所知,应用程序需要相对的布局才能正常工作。
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fafafa"
tools:context=".Activity.MainActivity">
<include
android:id="@+id/toolbarID"
layout="@layout/toolbar" />
<TextView
android:id="@+id/showWhenEmptyID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Add note"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_below="@id/toolbarID"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_above="@id/adView"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
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="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
答案 0 :(得分:1)
根据广告加载的响应,尝试在Java代码中的adView上使用VISIBILITY模式。
或
只需将可见性设置为xml,然后根据Java代码中广告加载的响应将其更改为VISIBLE。
在您的xml中:
ZipCode
在您的活动中:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:visibility="gone" //SET VISIBILITY GONE
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>