在GridView中显示原生AdMob广告 - Android

时间:2016-10-19 08:27:39

标签: android gridview android-gridview google-admob

我想在GridView布局中显示Native AdView。在适配器内部我创建了两个不同的视图,它扩展了ViewHolder并返回特定位置的特定视图。代码如下:

OnCreateViewHolder()

//Inflate Custom Layout for View
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View itemView = null;
    RecyclerView.ViewHolder vh = null;

    if (viewType == AD_TYPE) {

        itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.video_list_ad_view_layout, parent, false);
        vh = new VideoAdapter.AdViewHolder(itemView);

    } else {

        itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.video_card_layout, parent, false);
        vh = new VideoAdapter.VideoViewHolder(itemView);

    }

    return vh;
}

AdView持有人类:

//Separate AdViewHolder for displaying the Ads in the list
private static class AdViewHolder extends RecyclerView.ViewHolder {

    AdView mAdView;

    AdViewHolder(View view) {
        super(view);

        mAdView = (AdView) view.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(String.valueOf(R.string.test_device_id))
                .build();
        mAdView.loadAd(adRequest);
    }
}

VideoViewHOlder()

public class VideoViewHolder extends RecyclerView.ViewHolder {

    //Code is here for custom videoViewHolder

}

此广告显示在GridView布局中,包含其他网格项。我试图设置AdView的大小,但它并没有帮助我。

我需要一些解决方案,因此我可以将GridLayout中的NativeAd显示为GridItem。

图片可在以下位置找到: Google Plus POST with Image Here

0 个答案:

没有答案