AdView перекрывает последний элемент RecyclerView - PullRequest
0 голосов
/ 01 мая 2018

overlapped list item

Надеюсь, приложенный скриншот прояснит мою проблему. Последний элемент в списке RecyclerView перекрывается AdView.

Добавление нижнего отступа и поля к 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 голосов
/ 01 мая 2018

Высота баннеров с атрибутом adSize="BANNER" составляет 50 dp.

Самым простым решением может быть добавление нижнего отступа 50 дп (или более) к вашему RecyclerView и установке 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);
    }
});
0 голосов
/ 01 мая 2018

Попробуйте этот код ..

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

0 голосов
/ 01 мая 2018

Пользователь android:layout_above="" свойство внутри 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_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>
...