AdView与RecyclerView的最后一项重叠

时间:2018-05-01 14:34:08

标签: android android-recyclerview adview

overlapped list item

我希望附加的屏幕截图能让我的问题清晰明了,RecyclerView列表中的最后一项与AdView重叠。

添加底部填充&am​​p; RecyclerView的边距,AdView后面底部留空格,这是不可取的。

有没有办法设置滚动过度滚动或偏移?

任何快速的解决方案/建议都会有所帮助,在此先感谢。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvProverbs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:spanCount="4"
        />

    <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_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/ad_unit_id">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>

3 个答案:

答案 0 :(得分:5)

属性为adSize="BANNER"的横幅的高度为50 dp。

最简单的解决方案可能是向您的RecyclerView添加50 dp(或更高)的底部填充,并将clipToPadding设置为false

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvProverbs"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="50dp"
    android:clipToPadding="false"
    app:spanCount="4" />

如果您的AdView具有动态高度(或者您只想在加载AdView时添加填充),您只需从代码中动态设置填充。

例如:

adView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        recyclerView.setPadding(0, 0, 0, adView.getHeight());
        // recyclerView.setClipToPadding(false);
    }
});

答案 1 :(得分:0)

android:layout_above=""内的用户RecyclerView属性,并将AdView的ID设为。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvProverbs"
        android:layout_width="match_parent"
        android:layout_above="@+id/adView2"
        android:layout_height="match_parent"
        app:spanCount="4"
        />

    <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_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/ad_unit_id">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>

答案 2 :(得分:0)

试试这段代码..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvProverbs"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:spanCount="4"
    android:layout_above="@+id/adView2"
    android:layout_marginBottom="10dp"

    />

<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_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/ad_unit_id">
</com.google.android.gms.ads.AdView>