NativeExpressAdView导致recyclerview出现重大延迟

时间:2017-07-22 18:51:01

标签: android android-recyclerview admob android-support-library google-admob

我想在Recycler视图中显示NativeExpressAdView 我面临着主要的滞后问题,特别是在果冻豆和较低的设备上

Follwoing是我在“活动”中加载广告的代码

friends

现在在Fragment中我正在更新adpater,如下所示

friends

以下是我在适配器中的代码

  public NativeExpressAdView getNativeAd(AdSize adSize, boolean isFirstIndex) {
    final NativeExpressAdView nativeExpressAdView = new NativeExpressAdView(this);
    nativeExpressAdViews.add(nativeExpressAdView);
    if (isFirstIndex) {
        nativeExpressAdView.setAdUnitId(getString(R.string.test_adunit_id));
    } else {
        nativeExpressAdView.setAdUnitId(getString(R.string.test_adunit_id));
    }
    nativeExpressAdView.setAdSize(adSize);
    new Handler(getMainLooper()).post(new AdsRunnable(new WeakReference<NativeExpressAdView>(nativeExpressAdView)));
    return nativeExpressAdView;
}


static class AdsRunnable implements Runnable {

    private WeakReference<NativeExpressAdView> nativeExpressAdViewWeakReference;

    public AdsRunnable(WeakReference<NativeExpressAdView> nativeExpressAdViewWeakReference) {
        this.nativeExpressAdViewWeakReference = nativeExpressAdViewWeakReference;
    }

    @Override
    public void run() {
        if (nativeExpressAdViewWeakReference.get() != null) {
            nativeExpressAdViewWeakReference.get().loadAd(AdRequestManager.getAdRequest());
        }
    }
}

0 个答案:

没有答案