1
我有一個水平的RecyclerView。每個孩子都包含一個TextView和一個垂直的RecyclerView。垂直RecyclerView的子項只包含一個TextView。垂直RecyclerView裏面水平RecyclerView滯後滾動
垂直滾動非常平滑,但水平滾動滯後很多。 我試圖在onBindViewHolder而不是setAdapter中使用swapAdapter,但是這並沒有解決問題。我也嘗試更改數據集並調用notifyDataSetChanged(),但這也沒有幫助。
編輯
我剛剛發現的滾動是在橫向模式下居然順利。
水平RecyclerView.Adapter
private SparseArray<GroupArrayAdapter> adapters;
private ArrayList<Category> categories;
private Activity context;
public CategoryArrayAdapter(Context context, ArrayList<Category> categories) {
this.categories = categories;
this.context = (Activity)context;
adapters = new SparseArray<GroupArrayAdapter>();
for (int i = 0; i < categories.size(); i++) {
adapters.append(i, new GroupArrayAdapter(context, categories.get(i).getGroups()));
}
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public RecyclerView list;
public ViewHolder(View view) {
super(view);
name = (TextView) view.findViewById(R.id.lblCategoryName);
list = (RecyclerView) view.findViewById(R.id.lstGroups);
list.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
list.addItemDecoration(new GroupItemDecoration((int)context.getResources().getDimension(R.dimen.gap)));
//list.setAdapter(new GroupArrayAdapter(context, new ArrayList<Group>()));
}
}
@Override
public int getItemCount() {
return categories.size();
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
Category category = categories.get(position);
viewHolder.name.setText(category.getName());
viewHolder.list.swapAdapter(adapters.get(position), false);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_category, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
垂直RecyclerView.Adapter
private ArrayList<Group> groups;
public GroupArrayAdapter(Context context, ArrayList<Group> groups) {
this.groups = groups;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public ViewHolder(View view) {
super(view);
name = (TextView) view.findViewById(R.id.lblGroupName);
}
}
@Override
public int getItemCount() {
return groups.size();
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
Group group = groups.get(position);
viewHolder.name.setText(group.getName());
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = null;
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_group_text, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
請詳細說明如何和爲什麼這樣可以修復有機磷農藥問題 –
不工作,有沒有其他的想法? – Millerntor
這讓我對水平回收站的看法消失了。 –