我开发了代码,它在gridview中显示来自服务器的图像,但是stageredgridview无效。 以下是我的代码
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, LinearLayoutManager.VERTICAL);
CustomAdapter customAdapter = new CustomAdapter(MainActivity.this, personNames, personImages);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
recyclerView.setAdapter(customAdapter);
答案 0 :(得分:1)
试试这段代码
recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
if (recyclerView != null) {
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
}
private void setAdapter() {
imageAdapter = new ImageAdapter(this);
recyclerView.setAdapter(imageAdapter);
}