我遇到FirebaseRecyclerView问题。它只适用于StaggeredGridLayoutManager而不适用于GridLayoutManager,我不知道为什么。这是片段上的最小代码(我使用底部导航栏来更改片段):
public class xFragment extends Fragment{
//...
...//
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_search, container, false);
mGridLayoutManager = new GridLayoutManager(getActivity(), 3);
mDatabaseRef = FirebaseDatabase.getInstance().getReference("some_list");
modelRecyclerview = (RecyclerView)view.findViewById(R.id.grid);
modelRecyclerview.setHasFixedSize(true);
modelRecyclerview.setLayoutManager(mGridLayoutManager);
mFirebaseModelAdapter = new FirebaseRecyclerAdapter<Model,ModelViewHolder>
(Model.class, R.layout.grid_image, ModelViewHolder.class,
mDatabaseRef) {
@Override
protected void populateViewHolder(ModelViewHolder viewHolder,
Model model, int position) {
viewHolder.bindModel(model);
}
};
modelRecyclerview.setAdapter(mFirebaseModelAdapter);
Log.i(TAG,"Creation Success");
return view;
}
}
我的观看者代码:
public class ModelViewHolder extends RecyclerView.ViewHolder{
private static final String TAG = ModelViewHolder.class.getSimpleName();
public ImageView thumbnailImage;
private Context mContext;
public ModelViewHolder(View itemView) {
super(itemView);
thumbnailImage = (ImageView)itemView.findViewById(R.id.thumb_image);
mContext = itemView.getContext();
}
public void bindModel(Model firebaseNode) {
StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(myBucket).child(firebaseNode.getthumbnail());
// Load the image using Glide
Glide.with(mContext)
.using(new FirebaseImageLoader())
.load(storageReference)
.centerCrop()
.crossFade()
.into(thumbnailImage);
}
}
正如我之前所说的,当我用StaggeredGridLayoutManager替换GridLayoutManager时,我的列表中的所有缩略图都显示在我的模拟器上。但是,如果我使用GridLayoutManager,没有任何反应,我在控制台中没有任何错误,所以我被卡住了。有人能帮帮我吗?
谢谢