我正在以编程方式创建RecyclerView
为其分配适配器并添加项目装饰..但适配器不创建视图。当我删除项目装修其建筑罚款。项目装饰没有问题,因为我在xml创建的RecyclerView中使用了那段代码而没有任何问题。
示例代码如下:
RecyclerView recyclerView = new RecyclerView(context);
LinearLayout.LayoutParams recyclerViewLayoutParams =
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
recyclerViewLayoutParams.gravity = Gravity.START;
recyclerView.setLayoutParams(recyclerViewLayoutParams);
recyclerView.setClipToPadding(false);
ll_parent_layout.addView(recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(getParent());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setHasFixedSize(false);
// recyclerView.removeItemDecoration(gridSpacingItemDecoration);
// recyclerView.addItemDecoration(gridSpacingItemDecoration);
Adapter adapter = new Adapter(Activity.this, ResponseMap);
// linearSpacingItemDecoration = new LinearSpacingItemDecoration(R.dimen.margin8, adapter.getItemCount());
// recyclerView.removeItemDecoration(linearSpacingItemDecoration);
// recyclerView.addItemDecoration(linearSpacingItemDecoration);
recyclerView.setAdapter(adapter);
答案 0 :(得分:0)
问题在于如何对项目装饰器类进行初始化和重新初始化。我在一段时间后想到了