我尝试将 AdMob 集成到我的 XML 中,但它仅在应用程序顶部显示广告。 Image
在 Android Studio 中,它出现在正确的位置: Android Studio
我的 XML:
<FrameLayout xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/overlayContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="UselessParent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<TextView
android:id="@+id/bVersion"
style="@style/FakeSpinner"
android:layout_width="72dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:gravity="center"
android:textStyle="bold"
tools:text="VERSNM" />
<my.app.base.widget.NavFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<my.app.base.widget.GotoButton
android:id="@+id/bGoto"
style="?actionButtonStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/nav_goto_side_margin"
android:layout_marginEnd="@dimen/nav_goto_side_margin"
android:fontFamily="sans-serif-medium"
android:includeFontPadding="false"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:textSize="16sp"
tools:text="Long Name Of Book 123" />
<ImageButton
android:id="@+id/bLeft"
style="?actionButtonStyle"
android:layout_width="@dimen/nav_prevnext_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:contentDescription="@string/desc_previous_chapter"
android:scaleType="center"
android:src="@drawable/ic_nav_start_light" />
<ImageButton
android:id="@+id/bRight"
style="?actionButtonStyle"
android:layout_width="@dimen/nav_prevnext_width"
android:layout_height="match_parent"
android:layout_gravity="end"
android:contentDescription="@string/desc_next_chapter"
android:padding="16dp"
android:scaleType="center"
android:src="@drawable/ic_nav_end_light" />
</my.app.base.widget.NavFrameLayout>
</androidx.appcompat.widget.Toolbar>
<my.app.base.widget.TwofingerLinearLayout
android:id="@+id/splitRoot"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
tools:ignore="NestedWeights">
<my.app.base.verses.EmptyableRecyclerView
android:id="@+id/lsSplitView0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingStart="@dimen/text_side_padding"
android:paddingEnd="@dimen/text_side_padding"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" >
</my.app.base.verses.EmptyableRecyclerView>
<my.app.base.widget.LabeledSplitHandleButton
android:id="@+id/splitHandleButton"
android:layout_width="match_parent"
android:layout_height="@dimen/split_handle_thickness"
android:background="@null"
android:visibility="gone" />
<my.app.base.verses.EmptyableRecyclerView
android:id="@+id/lsSplitView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingStart="@dimen/text_side_padding"
android:paddingEnd="@dimen/text_side_padding"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" />
</my.app.base.widget.TwofingerLinearLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="FULL_BANNER"
ads:adUnitId="AD-UNIT-ID">
</com.google.android.gms.ads.AdView>
</LinearLayout>
<my.app.base.widget.Floater
android:id="@+id/floater"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:visibility="gone" />
</FrameLayout>
它只出现在正在运行的应用程序的顶部,已经在Android Studio中,它出现在我想要的位置。如何将此 AdMob 广告保留在 Android Studio 中的末尾?
最佳答案
在android中使用FrameLayout
ViewGroup时,您必须指定其子级的layout_gravity
。如果你不这样做,框架布局会将 subview 移动到顶部,这是FrameLayout
中 subview 的默认重力。要纠正这个问题,你所要做的就是
将 LinearLayout
的 layout_gravity
设置为 bottom
就像这样
由于 LinearLayout
是 admob 的父级,所以添加此
android:layout_gravity = "bottom"
到 LinearLayout
就在 android:orientation = "vertical"
之后或任何您希望它位于范围内的位置LinearLayout
ViewGroup。
关于java - Admob 仅显示在 XML 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61257708/