我已经在我的应用程序中实现了Admob原生广告。它被放置在我的回收器视图中每4个项目显示一次。
问题是:在广告被显示之前,一个空白会显示大约3到5秒,直到广告被加载。我需要帮助,以删除这个空白空间和加载广告之间的回收器视图项目只有当本机广告加载完全。我在下面附上了2张截图:显示广告之前和之后。
适配器代码如下所示。
public class MovieAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context mContext;
private List<Movie> mList;
private LayoutInflater mLayoutInflater;
private static final int DEFAULT_VIEW_TYPE = 1;
private static final int NATIVE_AD_VIEW_TYPE = 2;
public MovieAdapter(Context c, List<Movie> l) {
this(c, l, true, true);
}
public MovieAdapter(Context c, List<Movie> l, boolean wa, boolean wcl) {
mContext = c;
mList = l;
mLayoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getItemViewType(int position) {
if (position!=0 && position%4 == 0) {
return NATIVE_AD_VIEW_TYPE;
}
return DEFAULT_VIEW_TYPE;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v;
switch (viewType) {
default:
v = mLayoutInflater.inflate(R.layout.item_movie_card, viewGroup, false);
return new MyViewHolder(v);
case NATIVE_AD_VIEW_TYPE:
v = mLayoutInflater.inflate(R.layout.list_item_native_ad, viewGroup, false);
return new NativeAdViewHolder(v);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
if (!(holder instanceof MyViewHolder)) {
return;
}
MyViewHolder myViewHolder = (MyViewHolder) holder;
myViewHolder.tvName.setText(mList.get(position).getName());
myViewHolder.tvGenre.setText(mList.get(position).getGenre());
ControllerListener listener = new BaseControllerListener() {
@Override
public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
super.onFinalImageSet(id, imageInfo, animatable);
}
@Override
public void onFailure(String id, Throwable throwable) {
super.onFailure(id, throwable);
}
@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
super.onIntermediateImageFailed(id, throwable);
}
@Override
public void onIntermediateImageSet(String id, Object imageInfo) {
super.onIntermediateImageSet(id, imageInfo);
}
@Override
public void onRelease(String id) {
super.onRelease(id);
}
@Override
public void onSubmit(String id, Object callerContext) {
super.onSubmit(id, callerContext);
}
};
int w = 0;
if (myViewHolder.ivMovie.getLayoutParams().width == FrameLayout.LayoutParams.MATCH_PARENT
|| myViewHolder.ivMovie.getLayoutParams().width == FrameLayout.LayoutParams.WRAP_CONTENT) {
Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
try {
w = size.x;
} catch (Exception e) {
w = display.getWidth();
}
}
Uri uri = Uri.parse(DataUrl.getUrlCustom(mList.get(position).getUrlPhoto(), w));
DraweeController dc = Fresco.newDraweeControllerBuilder()
.setUri(uri)
.setTapToRetryEnabled(true)
.setControllerListener(listener)
.setOldController(myViewHolder.ivMovie.getController())
.build();
myViewHolder.ivMovie.setController(dc);
}
@Override
public int getItemCount() {
return mList.size();
}
public void addListItem(Movie c, int position) {
mList.add(c);
notifyItemInserted(position);
}
public void removeListItem(int position) {
mList.remove(position);
notifyItemRemoved(position);
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public SimpleDraweeView ivMovie;
public TextView tvName;
public TextView tvGenre;
public ImageButton imageButton;
public MyViewHolder(View itemView) {
super(itemView);
ivMovie = (SimpleDraweeView) itemView.findViewById(R.id.iv_car);
tvName = (TextView) itemView.findViewById(R.id.tv_model);
tvGenre = (TextView) itemView.findViewById(R.id.tv_brand);
imageButton = (ImageButton) itemView.findViewById(R.id.like_button);
}
@Override
public void onClick(View v) {
}
}
public class NativeAdViewHolder extends RecyclerView.ViewHolder {
private final NativeExpressAdView mNativeAd;
public NativeAdViewHolder(final View itemView) {
super(itemView);
mNativeAd = (NativeExpressAdView) itemView.findViewById(R.id.nativeAd);
mNativeAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
}
@Override
public void onAdClosed() {
super.onAdClosed();
}
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
@Override
public void onAdOpened() {
super.onAdOpened();
}
});
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mNativeAd.loadAd(adRequest);
}
}
}
布局文件-native_ad.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="132dp">
<com.google.android.gms.ads.NativeExpressAdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nativeAd"
ads:adSize="FULL_WIDTHx132"
ads:adUnitId="@string/native_ad_unit"/>
如果不是动态添加,可以将视图的可见性设置为未加载
public NativeAdViewHolder(final View itemView) {
super(itemView);
itemView.setVisibility(View.GONE);
mNativeAd = (NativeExpressAdView) itemView.findViewById(R.id.nativeAd);
mNativeAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
itemView.setVisibility(View.VISIBLE);
}
@Override
public void onAdClosed() {
super.onAdClosed();
}
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
@Override
public void onAdOpened() {
super.onAdOpened();
}
});
同样地,在onadfailedtoload中做为需求,我希望它能帮助你。
我试图在我的应用程序上添加原生admob广告,当我用原生Advanced的示例广告单元id测试时:CA-app-pub-3940256099942544/2247696110,它工作,我在我的应用程序上得到广告,但当我尝试我真正的原生广告id时,它不工作它不能加载广告,它显示空白屏幕,我向谷歌播放市场发布应用程序,我等了3天,但它没有加载,我从广告中得到以下警告。我怎样才能解决这个问题?请帮帮我,
这是调试器在运行代码时输出的内容: 2018-11-07 22:12:42.806497-0600CoverMe[7740:78040]未能在(UITabBar)上设置(keyPath)用户定义的检查属性:[setValue: forUndecedKey:]:此类不符合密钥keyPath的键值编码。2018-11-07 22:12:42.901273-0600CoverMe[7740:78040]
在用户关闭间隙广告后,我将在我的应用程序中添加奖励广告,它将显示一个屏幕,显示之前输入的文本,并在下方有一个显示奖励广告的视频按钮(我处于测试阶段,因此我还不包括任何奖励项目,只想先显示视频广告)。 当我使用Toast小部件来识别广告是否已加载时,我意识到广告已加载(显示“onRewardedAdLoade”文本)。但是,当我单击观看视频按钮时,似乎没有调用show RewardedVideo()
您好,我正在尝试将admob广告添加到已经使用swift上传到appstore的应用程序中。我在admob中制作了一个应用程序,复制了appid和ads ID,并显示了各自的横幅和间隙广告。这里的问题是,当我写这行时 测试广告完美地显示和工作,但当我评论这一行时,控制台中会显示以下错误。 请求错误:没有要显示的广告。 此消息以GADBannerViewDelegate的重载方法打印 请帮我解决这个
我正试图加载Admob原生广告。以前(在应用程序更新之前)广告经常显示,但现在它们不显示了。我已经在下面发布了代码、xml和Logcat。 代码 洛克卡特
我的代码看起来与原始代码一模一样(https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en#play)我确信我正确导入了所有内容,向我的AndroidManifest添加了元数据、活动和权限。 当我在我的设备上启动应用程序时,logcat 会给我以下内容: 找不到此Google Play服务资源和加载广告失