【发布时间】:2020-02-07 05:08:36
【问题描述】:
我正在制作一个 Android 应用,但在定位横幅时遇到了问题。
我有一个 Activity 作为片段的容器。我基本上想要根的滚动视图,然后是片段,最底部的广告。
这是我的 XML。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
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>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"></LinearLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:layout_constraintBottom_toBottomOf="parent"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintTop_toBottomOf="@id/fragment_container"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxx"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
这是布局的样子
基本上,广告直接放置在片段容器的下方,而不是附加到视口的底部。
我希望它附加到底部,然后让滚动视图同时滚动片段和广告。
这是让广告出现在底部的唯一方法(短期内):
<Constraint layout>
<Scroll View>
<Fragment container>
<Ad constraining to parent bottom>
但是,使用这种方法,滚动视图只会滚动片段并且不包含广告,这意味着您有时会看到广告与片段内容重叠。
所以我认为滚动视图必须是根视图。但是,我无法管理孩子让广告出现在滚动视图的底部,而不是孩子的底部边缘。
【问题讨论】:
-
可以使用相对布局吗?
-
@Karan - 将包含片段容器 + 广告的约束布局替换为相对布局会产生相同的结果。
-
如果你想要@SmallGrammer,我可以使用相对布局添加答案
-
这将有助于澄清。
标签: android admob fragment banner