簡體   English   中英

RecyclerView 和 NestedScrollView 底部的 Admob

[英]Admob in the bottom of RecyclerView and NestedScrollView

我有帶有 NestedScrollView 和工具欄的 RecyclerView。 我想將 adview 橫幅放在底部,這樣當用戶滾動時,橫幅總是可見的。 我不知道如何分隔這些視圖,因為當我將其更改為 LinearLayout 時,nestedscrollview 不起作用。 我的代碼如下所示:

<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>

嘗試使NestedScrollViewRecyclerView wrap_content的高度不匹配match_parent

  <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>

將您的布局包含在 LinearLayout 中並添加wight 10height 0dp

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="10"
    android:orientation="vertical">

    <androidx.coordinatorlayout.widget.CoordinatorLayout  
      android:layout_width="match_parent"
      android:layout_weight="10" <----- add this
      android:layout_height="0dp" <----- add this
      tools:context=".BenefitsActivity">
        ....
        ....
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    <com.google.android.gms.ads.AdView <----- add banner here
        android:id="@+id/abb_adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:visibility="gone"
        app:adSize="SMART_BANNER"
        app:adUnitId="@string/bannerAd" />
</LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM