我正在尝试通过传递活动中的值来更改跨度计数,值正在通过,但是跨度没有变化,我的代码就像,
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstance){
mStaggeredLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
View inflatedView = inflater.inflate(R.layout.start_fragment, container, false);
mRecyclerView = (RecyclerView)inflatedView.findViewById(R.id.list);
mRecyclerView.setLayoutManager(mStaggeredLayoutManager);
mRecyclerView.setHasFixedSize(true); //Data size is fixed - improves performance
mAdapter = new TravelListAdapter(getActivity());
mRecyclerView.setAdapter(mAdapter);
try{
int span = getArguments().getInt("grid",0);
mStaggeredLayoutManager.setSpanCount(span);
Toast.makeText(getActivity(), String.valueOf(span), Toast.LENGTH_SHORT).show();
}catch (Exception e){
}
return inflatedView;
}
为什么不起作用?
答案 0 :(得分:0)
如果更改交错网格布局管理器的跨度计数,则需要再次将其添加到回收器视图以应用更改。因此,首先传递跨度计数值然后将布局管理器添加到回收器视图可能会更好。