下面是我的Activity_main.xml文件
Activity_Main.xml屏幕截图
在我的Android应用主活动布局中,Google Admob位于顶部应用栏下方,我想将Admob标语切换到导航标语下方。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Light">
<LinearLayout
android:id="@+id/appbar_main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<LinearLayout
android:id="@+id/container_admob"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="7dp"
android:background="#00ffffff"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<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_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_3"
android:focusableInTouchMode="true"
android:layout_weight="1"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:paddingBottom="?android:attr/actionBarSize"
android:layout_weight="1"
android:visibility="visible" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/nav_bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:background="@android:color/white"
app:itemIconTint="@drawable/color_state_primary_2"
app:itemTextColor="@drawable/color_state_primary_2"
app:menu="@menu/menu_nav_bottom" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
在我的Android应用主活动布局中,Google Admob位于顶部应用栏下方,我想将Admob标语切换到导航标语下方。请帮助我解决此问题,谢谢!!
答案 0 :(得分:0)
从线性布局中删除addview并替换下面的代码
<android.support.design.widget.BottomNavigationView
android:id="@+id/nav_bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/adView"
android:layout_gravity="bottom"
android:background="@android:color/white"
app:itemIconTint="@drawable/color_state_primary_2"
app:itemTextColor="@drawable/color_state_primary_2"
app:menu="@menu/menu_nav_bottom" />
<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_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
答案 1 :(得分:0)
您可以尝试以下操作::
<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="LARGE_BANNER"
ads:adUnitId=".....">
</com.google.android.gms.ads.AdView>
答案 2 :(得分:0)
只需在底部导航视图中添加该行:
app:layout_constraintBottom_toTopOf="@id/adView"