Android RecyclerView和NestedScrollView底部的Admob

Android RecyclerView和NestedScrollView底部的Admob,android,admob,adview,Android,Admob,Adview,我有一个带有NestedScrollView和工具栏的RecyclerView。我想在底部放置adview横幅,这样当用户滚动时,横幅始终可见。我不知道如何分离这些视图,因为当我将nestedscrollview更改为LinearLayout时,它不工作。我的代码如下所示: <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/androi

我有一个带有NestedScrollView和工具栏的RecyclerView。我想在底部放置adview横幅,这样当用户滚动时,横幅始终可见。我不知道如何分离这些视图,因为当我将nestedscrollview更改为LinearLayout时,它不工作。我的代码如下所示:

<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BenefitsActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar_benefits"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_width="match_parent"
            android:background="#109689"
            app:title="@string/wlasciwosci"
            android:layout_height="?attr/actionBarSize">

        </androidx.appcompat.widget.Toolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:measureAllChildren="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="50dp"
            android:clipToPadding="false"
            android:background="@color/grey_background"
            android:id="@+id/benefits_recycler"/>

    </androidx.core.widget.NestedScrollView>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="bottom"
        ads:layout_constraintBottom_toBottomOf="parent"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

尝试将
嵌套滚动视图
回收视图
包装内容
匹配父视图

  <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:measureAllChildren="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="50dp"
            android:clipToPadding="false"
            android:background="@color/grey_background"
            android:id="@+id/benefits_recycler"/>

    </androidx.core.widget.NestedScrollView>

尝试将
嵌套滚动视图
回收视图
包装内容
匹配父视图

  <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:measureAllChildren="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="50dp"
            android:clipToPadding="false"
            android:background="@color/grey_background"
            android:id="@+id/benefits_recycler"/>

    </androidx.core.widget.NestedScrollView>


但如何在全屏宽度和高度上逐个设置工具栏、recyclerview和adview。在您的实现中,recyclerview中的最后一项被广告覆盖。我希望adview始终位于底部,是一个单独的视图。但是如何在全屏宽度和高度上逐个设置工具栏、recyclerview和adview。在您的实现中,recyclerview中的最后一项被广告覆盖。我希望adview始终位于底部,是一个单独的视图。