Я надеюсь, что приложенный снимок экрана проясняет мою проблему. Последний элемент в списке 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>
Пользовательское свойство 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>
Высота баннеров с атрибутом adSize = "BANNER"
- 50 dp.
Самым простым решением может быть добавление нижнего отступа 50 dp (или больше) к вашему 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);
}
});
Попробуйте этот код ..
<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>
Это вместе с android: layout_marginBottom = "работает лучше всего