我想在RecyclerView中加载广告广告已成功加载,但在滚动时会出现这么多延迟
以下是我在Adapter的OnBindViewHolder方法中编写的代码
如何解决这个滞后?
((DealHolder) holder).adcardView.post(new Runnable() { @Override public void run() { final NativeExpressAdView adView = new NativeExpressAdView(((DealHolder) holder).itemView.getContext()); final int adWidth = ((DealHolder) holder).adcardView.getWidth() - ((DealHolder) holder).adcardView.getPaddingLeft() - ((DealHolder) holder).adcardView.getPaddingRight(); final int adHeight = ((DealHolder) holder).adcardView.getHeight() - ((DealHolder) holder).adcardView.getPaddingBottom() - ((DealHolder) holder).adcardView.getPaddingTop(); final float scale = ((DealHolder) holder).adcardView.getResources().getDisplayMetrics().density; AdSize adSize = new AdSize((int) (adWidth / scale),(int) (adHeight / scale)); adView.setAdSize(adSize); adView.setAdUnitId(((DealHolder) holder).adcardView.getContext().getString(R.string.test_adunit_id)); AdRequest request = new AdRequest.Builder().addTestDevice("jjhjhbjhjhjhjhjhjhjh").build(); adView.loadAd(request); adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); } @Override public void onAdFailedToLoad(int i) { super.onAdFailedToLoad(i); } }); ((DealHolder) holder).adcardView.removeAllViews(); ((DealHolder) holder).adcardView.addView(adView); } });