【发布时间】:2018-11-14 19:19:02
【问题描述】:
我有recycler-view,里面有项目,可以垂直滚动。目前我实现的是项目像列表一样一个接一个地添加。我需要将它们并排放置。
喜欢下面的图片
我的输出是
我的回收站视图设置代码:
topicAdapter = new TopicAdapter(topicList, getActivity());
topicListView.setLayoutManager(new LinearLayoutManager(getActivity()));
topicListView.setAdapter(topicAdapter);
适配器代码为:
public class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.CategoryViewHolder> {
private List<Topic> topicList;
Context context;
public TopicAdapter(List<Topic> topicList, Context context) {
this.topicList = topicList;
this.context = context;
}
@Override
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//inflate the layout file
View groceryProductView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_suggested_topics, parent, false);
CategoryViewHolder holder = new CategoryViewHolder(groceryProductView);
return holder;
}
@Override
public void onBindViewHolder(CategoryViewHolder holder, final int position) {
holder.txtview.setText(topicList.get(position).getName());
}
@Override
public int getItemCount() {
return topicList.size();
}
public class CategoryViewHolder extends RecyclerView.ViewHolder {
TextView txtview;
public CategoryViewHolder(View view) {
super(view);
txtview = view.findViewById(R.id.titleView);
}
}
}
【问题讨论】:
-
setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true)); -
添加你的适配器布局代码这意味着适配器在定义布局xml代码
标签: android android-recyclerview recyclerview-layout