我有问题在水平回收视图中滚动.例如,如果我有10个项目,第一次,我能够滚动到最后一项,但如果我去第一项,然后再次滚动到最后一项,它不会移动到最后一项.
这个问题是否与滚动有关,如果是这种情况,我是否应该覆盖滚动.
这是我的片段类声明
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); mRecyclerView = (RecyclerView)v. findViewById(R.id.recycler_view); adapter = new MyRecyclerAdapter(getActivity()); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(adapter);
并在我的适配器中
public class MyRecyclerAdapter extends RecyclerView.Adapter{ private Context mContext; JobSiteActivity mjobSiteActivity; ImageLoader loader = null; public MyRecyclerAdapter(Activity activity) { this.mContext = activity; mjobSiteActivity = (JobSiteActivity)activity; loader = mjobSiteActivity.getImageLoader(); } @Override public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.image_detail_fragment, null); CustomViewHolder viewHolder = new CustomViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(CustomViewHolder customViewHolder, int i) { //FeedItem feedItem = feedItemList.get(i); //Download image using picasso library /* Picasso.with(mContext).load(feedItem.getThumbnail()) .error(R.drawable.placeholder) .placeholder(R.drawable.placeholder) .into(customViewHolder.imageView);*/ customViewHolder.imageView.setImageUrl(Images.imageThumbUrls[i], loader); customViewHolder.imageView.setOnClickListener(clickListener); customViewHolder.imageView.setTag(customViewHolder); //Setting text view title } @Override public int getItemCount() { //return (null != feedItemList ? feedItemList.size() : 0); return Images.imageThumbUrls.length; } public class CustomViewHolder extends RecyclerView.ViewHolder { protected NetworkImageView imageView; public CustomViewHolder(View view) { super(view); this.imageView = (NetworkImageView) view.findViewById(R.id.imageView); } } View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View view) { CustomViewHolder holder = (CustomViewHolder) view.getTag(); int position = holder.getLayoutPosition(); int position1 = holder.getAdapterPosition(); Toast.makeText(mContext, "layoutPs"+position+"adapPos"+position, Toast.LENGTH_SHORT).show(); } };
}
我正在尝试使用V17 leanback附带的水平网格视图,它也扩展了recycleView,但我仍然面临着类似的问题,
如果我尝试在运行时将任何项目添加到回收器视图中,例如在拍照时,它也没有被添加,它分配空间并且它是空的?在这个问题上很难理解或调试.