[英]Admob in the bottom of RecyclerView and NestedScrollView
I have RecyclerView with NestedScrollView and Toolbar.我有带有 NestedScrollView 和工具栏的 RecyclerView。 I want to place adview banner in the bottom so when a user is scrolling the banner is always visible.我想将 adview 横幅放在底部,这样当用户滚动时,横幅总是可见的。 I don't know how to separate these views because nestedscrollview is not working when I changed it to LinearLayout.我不知道如何分隔这些视图,因为当我将其更改为 LinearLayout 时,nestedscrollview 不起作用。 My code looks like this:我的代码如下所示:
<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>
try make height of NestedScrollView
and RecyclerView
wrap_content
not match_parent
尝试使NestedScrollView
和RecyclerView
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>
Enclose your layout in LinearLayout and add wight 10
and height 0dp
将您的布局包含在 LinearLayout 中并添加wight 10
和height 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.