在 RecyclerView 中加载 AdView 时出现问题
Problems loading AdView inside a RecyclerView
我一直在 Whosebug 中寻找如何将 AdView
集成到 RecyclerView
中。我一直在关注这些帖子:
,
基本上,方法是在 onCreateViewHolder
或 ViewHolder
.
的构造函数中调用 loadAd
无论如何,这是我的实现:
JAVA
public class AdExpressViewHolder extends RecyclerView.ViewHolder {
public AdExpressViewHolder(View itemView) {
super(itemView);
final AdView adView = (AdView)itemView.findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
.build();
adView.loadAd(request);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ads:adUnitId="**********************"
ads:adSize="BANNER">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</RelativeLayout>
问题是: 当我滚动 RecyclerView 时,它似乎在 UI 线程上加载,因为它卡住了,只有第一次。其他时间还可以。
这是演示它的视频:
如您所见,第一个挡住了 UI,但第二个没有挡住。
我做错了什么?
提前致谢。
编辑
我尝试在 activity 中加载常规 AdView
,已修复。它有效并且似乎没有加载到 UI 线程中。似乎这只是发生在 RecyclerView
.
3 周后,我完成了方法分析,这就是我得出的结论:
你可以意识到红点。这些是 2 个不同的 AdView
加载,而其余的是我的 38 个正常自定义视图。
更具体地说,这些是功能,所以它是关于 100% AdView
:
这似乎是 Android 的 Ads SDK 的一个错误并且它没有被修复,至少直到 v9.4.0。
更多信息在这里:
https://groups.google.com/forum/#!searchin/google-admob-ads-sdk/ui$20thread%7Csort:relevance/google-admob-ads-sdk/k4IFZA_QGT4/3gMHaCPPBQAJ
我一直在 Whosebug 中寻找如何将 AdView
集成到 RecyclerView
中。我一直在关注这些帖子:
基本上,方法是在 onCreateViewHolder
或 ViewHolder
.
loadAd
无论如何,这是我的实现:
JAVA
public class AdExpressViewHolder extends RecyclerView.ViewHolder {
public AdExpressViewHolder(View itemView) {
super(itemView);
final AdView adView = (AdView)itemView.findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
.build();
adView.loadAd(request);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ads:adUnitId="**********************"
ads:adSize="BANNER">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</RelativeLayout>
问题是: 当我滚动 RecyclerView 时,它似乎在 UI 线程上加载,因为它卡住了,只有第一次。其他时间还可以。
这是演示它的视频:
如您所见,第一个挡住了 UI,但第二个没有挡住。
我做错了什么?
提前致谢。
编辑
我尝试在 activity 中加载常规 AdView
,已修复。它有效并且似乎没有加载到 UI 线程中。似乎这只是发生在 RecyclerView
.
3 周后,我完成了方法分析,这就是我得出的结论:
你可以意识到红点。这些是 2 个不同的 AdView
加载,而其余的是我的 38 个正常自定义视图。
更具体地说,这些是功能,所以它是关于 100% AdView
:
这似乎是 Android 的 Ads SDK 的一个错误并且它没有被修复,至少直到 v9.4.0。
更多信息在这里: https://groups.google.com/forum/#!searchin/google-admob-ads-sdk/ui$20thread%7Csort:relevance/google-admob-ads-sdk/k4IFZA_QGT4/3gMHaCPPBQAJ