Recycler View flickering issue with GoogleAdmobNative Advanced Ads

541 views
Skip to first unread message

ruth...@publicvibe.com

unread,
May 15, 2018, 7:33:35 AM5/15/18
to Google Mobile Ads SDK Developers
Hello Team,

I am working with AdmobNativeAdvanced Ad integration in recycler views. I pref-etching the ads for better performance. After implementing ads in recycler views I am getting flickering issues when scrolling. If I am using some sample data in place of appending admob data it looks fine. Can you please verify my code and let me know where the implementation was wrong?

getItemViewType:

int adpos = getAdIndex(position);
NativeAd ad = mAdmobAdPlacer.getAdForIndex(adpos);
if (ad != null) {
return ad instanceof NativeAppInstallAd ? VIEW_TYPE_INSTALL_AD : VIEW_TYPE_CONTENT_AD;
} else {
return VIEW_TYPE_CONTENT_AD;
}



OnCreateViewHolder:



else if (type == VIEW_TYPE_INSTALL_AD) {
// return new NativeHolder(getInstallAdsLayoutContext().inflateView(parent));
View view = LayoutInflater.from(activity)
.inflate(R.layout.ad_installlistview_item, parent, false);
InstallAdViewHolder holder = new InstallAdViewHolder(view);
return holder;
} else if (type == VIEW_TYPE_CONTENT_AD) {
//return new NativeHolder(getContentAdsLayoutContext().inflateView(parent));
View view = LayoutInflater.from(activity)
.inflate(R.layout.ad_contentlistview_item, parent, false);
ContentAdViewHolder holder = new ContentAdViewHolder(view);
return holder;
}

OnBindViewHolder:

else if (itemViewType == VIEW_TYPE_INSTALL_AD) {
int adPos = getAdIndex(position);
NativeAppInstallAd ad1 = (NativeAppInstallAd) mAdmobAdPlacer.getAdForIndex(adPos);
if (ad1 == null) {
viewHolder.itemView.setVisibility(View.GONE);
RelativeLayout linear = (RelativeLayout) viewHolder.itemView.findViewById(R.id.linearAdView);
linear.setVisibility(View.GONE);
} else {
populateAppInstallAdView(ad1, (NativeAppInstallAdView) viewHolder.itemView);
}
} else if (itemViewType == VIEW_TYPE_CONTENT_AD) {
int adPos = getAdIndex(position);
NativeContentAd ad2 = (NativeContentAd) mAdmobAdPlacer.getAdForIndex(adPos);
if (ad2 == null) {
viewHolder.itemView.setVisibility(View.GONE);
RelativeLayout linear = (RelativeLayout) viewHolder.itemView.findViewById(R.id.linearAdViewContent);
linear.setVisibility(View.GONE);
} else {
populateContentAdView(ad2, (NativeContentAdView) viewHolder.itemView);
}
}


Following is the layout code:

<com.google.android.gms.ads.formats.NativeContentAdView 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:id="@+id/contentAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">


<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:id="@+id/linearAdViewContent"
android:layout_width="match_parent"
android:layout_height="@dimen/news_card_lite_img_height"
android:background="@color/white"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:visibility="visible">

<ImageView
android:id="@+id/ivLogo"
android:layout_width="@dimen/news_card_lite_img_width"
android:layout_height="@dimen/news_card_lite_img_width"
android:layout_gravity="center"
android:gravity="center"
android:scaleType="fitXY"
android:src="@color/aboutus_bg" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/ivLogo"
android:background="@color/white"
android:paddingLeft="@dimen/lite_content_padding">

<com.newsdistill.mobile.utils.CustomFontTextView
android:id="@+id/tvHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:paddingBottom="3dp"
android:paddingTop="0dp"
android:text="djfhksjdfhksjdfhksjdhfksjd"
android:textColor="?news_card_title"
android:textSize="@dimen/home_lite_title_size"
app:customTypeface="@string/font_semi_bold" />

<com.newsdistill.mobile.utils.CustomFontTextView
android:id="@+id/tvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvHeader"
android:ellipsize="end"
android:maxLines="3"
android:text="kjhfksjdfhksjdhfkjsdhkfj"
android:textColor="@color/news_card_genre"
android:textSize="@dimen/homelight_weight_sourcesize"
app:customTypeface="@string/font_regular" />

<com.newsdistill.mobile.utils.CustomFontTextView
android:id="@+id/btnAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/rounded_adborder1"
android:capitalize="sentences"
android:gravity="center_vertical"
android:inputType="textCapSentences"
android:orientation="horizontal"
android:padding="6dp"
android:textColor="@color/adfill_txt"
android:textSize="@dimen/ads_install_txt"
app:customTypeface="@string/font_regular"
tools:text="@string/ad" />

<com.newsdistill.mobile.utils.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/rounded_filladborder"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="1dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="1dp"
android:text="@string/ad"
android:textColor="@color/adfill_txt"
android:textSize="@dimen/news_card_source_txt"
app:customTypeface="@string/font_regular" />
</RelativeLayout>

</RelativeLayout>
</android.support.v7.widget.CardView>
</com.google.android.gms.ads.formats.NativeContentAdView>


Please find the below screen shots for more clarity:





In case of first image I am not appending the Admob data through bindviewholder. Its working fine in this case.

Hope you could help me out.

Thanks,
Anjaneya Ruthvik



mobileadssdk-a...@google.com

unread,
May 15, 2018, 3:34:16 PM5/15/18
to ruth...@publicvibe.com, Google Mobile Ads SDK Developers
Hi Ruthvik,

Thanks for reaching out to us. So you are prefetching and even caching the response? Or you are discarding the ad as soon as it is shown to the user? Or the OnBindViewHolder method is calling a new Ad all the time? This looks like an implementation related issue and I would suggest that you start with our sample apps on RecyclerView to get things started and let us know if you need more guidance with your integration and we would be able to help you. 

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

mobileadssdk-a...@google.com

unread,
May 16, 2018, 3:07:37 PM5/16/18
to ruth...@publicvibe.com, Google Mobile Ads SDK Developers
Hi Ruthvik,

Can you provide us a sample app for us to debug this? I'm unable to reproduce this issue with our sample apps. It certainly looks like an implementation issue only. Also, can you confirm whether you are noticing this issue on the latest version of the SDK? And is it happening with any specific creative?

Moving forward, please continue the discussion on the forum thread after providing the requested information privately as it might help other community users to go through this thread if they have similar issues.


Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Hermawan Winata

unread,
Jun 25, 2018, 12:16:50 AM6/25/18
to Google Mobile Ads SDK Developers
Hi,

Is there any sample apps for DFP Native Ads Advanced Usage with RecyclerView to show the correct usage? I could only find BannerAds with RecyclerView. I think there are a lot of differences in implementation between the two, for example should we destroy the AdView and the NativeAd in `onViewRecycled(…)` to conserve memory and should we have 1 AdView for 1 NativeAd. 

Thank you.

mobileadssdk-a...@google.com

unread,
Jun 25, 2018, 2:55:06 PM6/25/18
to Hermawan Winata, Google Mobile Ads SDK Developers
Hi there,

Thanks for reaching out to us. While we do not have any sample app with Native Advanced and RecyclerView, you can use the one with BannerView and let us know if you are having any issues. We would be happy to assist you.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Reply all
Reply to author
Forward
0 new messages