我有使用GridLayoutManager的recyclerView, recyclerView项目由ImageView和自定义进度组成,随着时间的推移更新,但我不需要每次都加载位图,只需要进度。这就是我使用magazineId的原因,当它只是在那种情况下是空的加载位图,但无论如何它会不时地加载位图,这与我在使用LinearLayoutManager时没有相同。
@Override
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.library_item, parent, false);
SimpleViewHolder viewHolder = new SimpleViewHolder(view);
viewHolder.id = "NONE";
return viewHolder;
}
@Override
public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
final Magazine magazineItem = magazines.get(position);
String magazineId = magazineItem.getId();
if (!viewHolder.magazineId.equals(magazines.get(position).getId())) {
viewHolder.layoutCoverContainer.setLayoutParams(new LinearLayout.LayoutParams(200, coverHeigth));
gDisplayImage(new GlideImage(magazines.get(position).getFirstPage(), true), viewHolder.glideView);
viewHolder.magazineId = magazines.get(position).getId();
}
viewHolder.customProgress.setPercent(percent);
}
public void setMagazines(List<Magazine> allMagazines) {
if (allMagazines != null) {
if (magazines == null) {
magazines = new ArrayList<Magazine>();
} else {
magazines.clear();
}
if (allMagazines != null) {
magazines.addAll(allMagazines);
} else {
magazines.clear();
}
}
notifyDataSetChanged();
}
public class SimpleViewHolder extends RecyclerView.ViewHolder {
GlideViewglideView;
String magazineId;}
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:clipToPadding="false" />
private void setUpSwipRecyclerView() {
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(),2));
mRecyclerView.setAdapter(libraryAdapter);
}