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