我正在使用以下布局将内容布局置于adview顶部。该adview应该位于屏幕底部。广告浏览高度为wrap_content
。 top_view_layout
应该跨越屏幕的其余部分。但是,一个用户发送了一个带有adview的屏幕截图,占据了屏幕的一半(该adview在用户的屏幕截图中实际上是空白的,因此我怀疑广告没有显示或被阻止)。这种布局怎么可能?
这是布局:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/top_view_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/adView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:adSize="SMART_BANNER"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_view_layout"/>
</androidx.constraintlayout.widget.ConstraintLayout>
更新:用户确认已启用广告拦截器。关闭广告拦截器后,布局显示良好。显然,广告拦截器正在将AdView布局高度形式从wrap_content
更改为0dp
,以便AdView占据半屏。但是,有没有一种方法可以解决该问题,即使打开了广告拦截器也是如此?
答案 0 :(得分:1)
解决方案:
这是使用简单解决方案的ConstraintLayout中的布局错误,只需删除以下行:
app:layout_constraintTop_toBottomOf="@+id/top_view_layout"
来自AdView
,您的错误将得到解决。
为什么?通过将top layout
的顶部设置为底部,将AdView
的底部设置为顶部,您实际上是将它们链接在一起,以使它们具有相等的height
屏幕。因此,错误。
尝试一下,如果有其他问题,请在此处进行更新。