Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以将admob本机广告与StaggedGridLayoutManager一起使用?_Android_Android Recyclerview_Admob_Staggeredgridlayout - Fatal编程技术网

Android 是否可以将admob本机广告与StaggedGridLayoutManager一起使用?

Android 是否可以将admob本机广告与StaggedGridLayoutManager一起使用?,android,android-recyclerview,admob,staggeredgridlayout,Android,Android Recyclerview,Admob,Staggeredgridlayout,我遵循以下步骤将admob advanced native ads添加到我的RecycleServiceAdapter中。我可以很容易地显示中型和大型广告类型的广告。但我的应用程序也包括交错网格作为视图类型。但我不能用这种格式显示广告,我只能在广告行中看到白色屏幕。我认为这是大小问题,但admob中没有交错行格式的大小。它将我的最小宽度值限制为280dp。有没有办法以交错格式显示广告?如果没有,那么你能建议我另一家广告提供商,比如admob来解决这个问题吗?我使用GridLayoutManage

我遵循以下步骤将admob advanced native ads添加到我的RecycleServiceAdapter中。我可以很容易地显示中型和大型广告类型的广告。但我的应用程序也包括交错网格作为视图类型。但我不能用这种格式显示广告,我只能在广告行中看到白色屏幕。我认为这是大小问题,但admob中没有交错行格式的大小。它将我的最小宽度值限制为280dp。有没有办法以交错格式显示广告?如果没有,那么你能建议我另一家广告提供商,比如admob来解决这个问题吗?

我使用GridLayoutManager而不是StaggedGridLayoutManager解决了这个问题,多亏了Chris的参与

这是解决办法

  public static final int ITEMS_PER_AD = 8;

  private GridLayoutManager mLayoutManager;

  // The Native Express ad height.
  private static final int NATIVE_EXPRESS_AD_HEIGHT = 150;

 // The Native Express ad unit ID.
 private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/1072772517";

 // The RecyclerView that holds and displays Native Express ads and menu items.
 private RecyclerView mRecyclerView;

 // List of Native Express ads and MenuItems that populate the RecyclerView.
 private List<Object> mRecyclerViewItems = new ArrayList<>();

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mLayoutManager = new GridLayoutManager(this, 2);
    mLayoutManager.setSpanSizeLookup(new 
    GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        if (position % MainActivity.ITEMS_PER_AD == 0) {
            return 2;
        }
        return 1;
    }
    });

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    // Use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView.
    mRecyclerView.setHasFixedSize(true);

    // Specify a linear layout manager.
    mRecyclerView.setLayoutManager(mLayoutManager);

   // Update the RecyclerView item's list with menu items and Native Express ads.
   addMenuItemsFromJson();
   addNativeExpressAds();
   setUpAndLoadNativeExpressAds();

   // Specify an adapter.
   RecyclerView.Adapter adapter = new RecyclerViewAdapter(this, mRecyclerViewItems);
   mRecyclerView.setAdapter(adapter);
}
public static final int ITEMS\u PER\u AD=8;
私人GridLayoutManager mLayoutManager;
//本地人表达广告高度。
专用静态最终整数本机快速AD高度=150;
//本机Express ad单元ID。
专用静态最终字符串AD_UNIT_ID=“ca-app-pub-394025609994254/1072772517”;
//保存和显示本机Express广告和菜单项的RecyclerView。
私人回收视图mRecyclerView;
//填充RecyclerView的本机Express广告和菜单项列表。
私有列表MRECYCLerviceItems=newArrayList();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLayoutManager=新的GridLayoutManager(这个,2);
mLayoutManager.SetPansizeLookup(新)
GridLayoutManager.SpanSizeLookup(){
@凌驾
公共整数getSpanSize(整数位置){
如果(位置%MainActivity.ITEMS每_广告=0){
返回2;
}
返回1;
}
});
mRecyclerView=(RecyclerView)findViewById(R.id.recycler\u视图);
//如果您知道这些更改,请使用此设置提高性能
//在内容中,不要更改RecyclerView的布局大小。
mRecyclerView.setHasFixedSize(true);
//指定线性布局管理器。
mRecyclerView.setLayoutManager(mllayoutmanager);
//使用菜单项和Native Express广告更新RecyclerView项目的列表。
addMenuItemsFromJson();
addNativeExpressAds();
setUpAndLoadNativeExpressAds();
//指定一个适配器。
Adapter Adapter=新的RecycleServiceAdapter(这是MRECycleServiceItems);
mRecyclerView.setAdapter(适配器);
}
如果您可以按照,您可以找到其他类和布局。因为这是该项目的修改版本。
我希望这个解决方案能对像我这样的人起作用。

多亏了克里斯,我用GridLayoutManager而不是StaggedGridLayoutManager解决了这个问题

这是解决办法

  public static final int ITEMS_PER_AD = 8;

  private GridLayoutManager mLayoutManager;

  // The Native Express ad height.
  private static final int NATIVE_EXPRESS_AD_HEIGHT = 150;

 // The Native Express ad unit ID.
 private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/1072772517";

 // The RecyclerView that holds and displays Native Express ads and menu items.
 private RecyclerView mRecyclerView;

 // List of Native Express ads and MenuItems that populate the RecyclerView.
 private List<Object> mRecyclerViewItems = new ArrayList<>();

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mLayoutManager = new GridLayoutManager(this, 2);
    mLayoutManager.setSpanSizeLookup(new 
    GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        if (position % MainActivity.ITEMS_PER_AD == 0) {
            return 2;
        }
        return 1;
    }
    });

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    // Use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView.
    mRecyclerView.setHasFixedSize(true);

    // Specify a linear layout manager.
    mRecyclerView.setLayoutManager(mLayoutManager);

   // Update the RecyclerView item's list with menu items and Native Express ads.
   addMenuItemsFromJson();
   addNativeExpressAds();
   setUpAndLoadNativeExpressAds();

   // Specify an adapter.
   RecyclerView.Adapter adapter = new RecyclerViewAdapter(this, mRecyclerViewItems);
   mRecyclerView.setAdapter(adapter);
}
public static final int ITEMS\u PER\u AD=8;
私人GridLayoutManager mLayoutManager;
//本地人表达广告高度。
专用静态最终整数本机快速AD高度=150;
//本机Express ad单元ID。
专用静态最终字符串AD_UNIT_ID=“ca-app-pub-394025609994254/1072772517”;
//保存和显示本机Express广告和菜单项的RecyclerView。
私人回收视图mRecyclerView;
//填充RecyclerView的本机Express广告和菜单项列表。
私有列表MRECYCLerviceItems=newArrayList();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLayoutManager=新的GridLayoutManager(这个,2);
mLayoutManager.SetPansizeLookup(新)
GridLayoutManager.SpanSizeLookup(){
@凌驾
公共整数getSpanSize(整数位置){
如果(位置%MainActivity.ITEMS每_广告=0){
返回2;
}
返回1;
}
});
mRecyclerView=(RecyclerView)findViewById(R.id.recycler\u视图);
//如果您知道这些更改,请使用此设置提高性能
//在内容中,不要更改RecyclerView的布局大小。
mRecyclerView.setHasFixedSize(true);
//指定线性布局管理器。
mRecyclerView.setLayoutManager(mllayoutmanager);
//使用菜单项和Native Express广告更新RecyclerView项目的列表。
addMenuItemsFromJson();
addNativeExpressAds();
setUpAndLoadNativeExpressAds();
//指定一个适配器。
Adapter Adapter=新的RecycleServiceAdapter(这是MRECycleServiceItems);
mRecyclerView.setAdapter(适配器);
}
如果您可以按照,您可以找到其他类和布局。因为这是该项目的修改版本。
我希望这个解决方案能对像我这样的人起作用。

完美的解决方案@kalpesh mayani以上两个链接都不存在,请您用正确的链接更新它们好吗?完美的解决方案@kalpesh mayani上述两个链接都不存在,请用正确的链接更新它们好吗?