我遇到了这个问题
我正在使用交错网格视图,它有两列和单列的组合..像这样的东西
一切正常,直到我上下滚动几次,它随机变为这样的东西
再画几卷,结果是这样的
我不知道为什么,而且非常随机。每次显示页面时,我都尝试执行 notifyDataSetChanged,但似乎没有做任何事情
这是我的仪表板的代码
public class DashboardStaggered extends Fragment {
RecyclerView mRecyclerView;
View v;
MasonryAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("MASONRY", "onCreateView");
super.onCreate(savedInstanceState);
if(v==null) {
Log.d("MASONRY", "v is NULL recreating");
v = inflater.inflate(R.layout.activity_dashboard_staggered, container, false);
setupRecyclerView();
}else{
Log.d("MASONRY", "v is NOT NULL");
}
return v;
}
private void setupRecyclerView(){
mRecyclerView = (RecyclerView) v.findViewById(R.id.masonry_grid);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
adapter = new MasonryAdapter(getActivity(),this);
mRecyclerView.setAdapter(adapter);
SpacesItemDecoration decoration = new SpacesItemDecoration(12);
mRecyclerView.addItemDecoration(decoration);
adapter.notifyDataSetChanged();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
@Override
public void onResume() {
super.onResume();
Log.d("MASONRY", "onResume");
if(mRecyclerView==null) {
setupRecyclerView();
}
}
@Override
public void onPause() {
super.onPause();
Log.d("MASONRY", "onPause");
}
}
如果需要,我也可以发布适配器。任何建议都是高度赞赏的人。
适配器代码在这里(不想让帖子乱七八糟)http://pastebin.com/QkZbjjp1