这确实很难实现。我的活动具有以下XML。我想在底部导航上方放置一个广告,该怎么做?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="end">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:titleTextColor="@android:color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:subtitleTextColor="@android:color/white"/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_navigation"
android:layout_below="@+id/toolbar_container">
<android.support.design.widget.AppBarLayout
android:id="@+id/tab_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabGravity="fill"
app:tabMode="scrollable">
</android.support.design.widget.TabLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/fab_margin"
android:layout_above="@+id/ad_view"
app:srcCompat="@drawable/ic_filter_list_white_24dp"
android:layout_alignParentRight="true" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_above="@+id/bottom_navigation"
android:background="@color/colorAccent" />
<!--<com.google.android.gms.ads.AdView-->
<!--xmlns:ads="http://schemas.android.com/apk/res-auto"-->
<!--android:id="@+id/ad_view"-->
<!--android:layout_above="@+id/bottom_navigation"-->
<!--android:layout_alignParentBottom="true"-->
<!--ads:adSize="BANNER"-->
<!--ads:adUnitId="ca-app-pub-3940256099942544/6300978111"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"/>-->
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:elevation="12dp"
app:itemIconTint="@drawable/bottom_main_nav_item_style"
app:itemTextColor="@drawable/bottom_main_nav_item_style"
app:menu="@menu/bottom_nav_items" />
</RelativeLayout>
<LinearLayout
android:id="@+id/platforms_filter_drawer"
android:background="@color/colorPrimaryD"
android:layout_width="215dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="vertical" >
<RelativeLayout
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/filter_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:text="FILTER"
android:textColor="@android:color/white"
android:textSize="@dimen/header" />
<Button
android:textColor="@android:color/white"
android:textSize="@dimen/header"
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="invisible"
android:text="CLEAR"
android:backgroundTint="@color/md_red_600"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/md_grey_600" />
<ListView
android:id="@+id/left_drawer_list"
android:layout_width="215dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
当前评论的AdView位于底部导航下方。我非常努力地将其放置在底部导航上方和fab按钮下方,但是无论我如何尝试,它似乎都无法正常工作。谢谢!
答案 0 :(得分:1)
尝试在底部导航栏和广告周围添加LinearLayout,然后将方向设置为垂直视图,如下所示
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="end">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:titleTextColor="@android:color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:subtitleTextColor="@android:color/white"/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_navigation"
android:layout_below="@+id/toolbar_container">
<android.support.design.widget.AppBarLayout
android:id="@+id/tab_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabGravity="fill"
app:tabMode="scrollable">
</android.support.design.widget.TabLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/fab_margin"
android:layout_above="@+id/ad_view"
app:srcCompat="@drawable/ic_filter_list_white_24dp"
android:layout_alignParentRight="true" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_above="@+id/bottom_navigation"
android:background="@color/colorAccent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/ad_view"
android:layout_above="@+id/bottom_navigation"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:elevation="12dp"
app:itemIconTint="@drawable/bottom_main_nav_item_style"
app:itemTextColor="@drawable/bottom_main_nav_item_style"
app:menu="@menu/bottom_nav_items" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/platforms_filter_drawer"
android:background="@color/colorPrimaryD"
android:layout_width="215dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="vertical" >
<RelativeLayout
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/filter_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:text="FILTER"
android:textColor="@android:color/white"
android:textSize="@dimen/header" />
<Button
android:textColor="@android:color/white"
android:textSize="@dimen/header"
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="invisible"
android:text="CLEAR"
android:backgroundTint="@color/md_red_600"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/md_grey_600" />
<ListView
android:id="@+id/left_drawer_list"
android:layout_width="215dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>