第一个是下图中的一个.项目之一(如图像中的红色边框)粘在屏幕的某个随机部分,并阻止其他项目.当该项目的真实版本在屏幕上可见时,它将消失.
滚动这个长的RecyclerVIEw太快的另一个问题是粘贴onClick效果.一些项目变得可见,就像有人在按压它们.
有关我的适配器的这些问题,还是RecyclerVIEw的常见问题?这是我的适配器
public class SimpleListItemRecyclerAdapter extends RecyclerVIEw.Adapter<SimpleListItemRecyclerAdapter.ListItemVIEwHolder> { Context context; ArrayList<RecyclerItemmodel> List; OnRecyclerVIEwItemClickListener onRecyclerVIEwItemClickListener; private int lastposition = -1; private boolean isClickable; public SimpleListItemRecyclerAdapter(ArrayList<RecyclerItemmodel> List,_FragmentTemplate fragment) { this.List = List; this.context = fragment.getActivity(); try { this.onRecyclerVIEwItemClickListener = (OnRecyclerVIEwItemClickListener) fragment; isClickable = true; } catch (ClassCastException e) { isClickable = false; } setHasStableIDs(true); } @OverrIDe public ListItemVIEwHolder onCreateVIEwHolder(VIEwGroup parent,int vIEwType) { VIEw itemVIEw = LayoutInflater.from(parent.getContext()). inflate(R.layout.item_sub_main_List_single_text,parent,false); return new ListItemVIEwHolder(itemVIEw,onRecyclerVIEwItemClickListener,isClickable,List.get(0).getHeight()); } @OverrIDe public voID onBindVIEwHolder(ListItemVIEwHolder holder,int position) { final RecyclerItemmodel recyclerItem = List.get(position); if (recyclerItem.isBackgroundcolorSpecifIEd()) holder.itemVIEw.setBackgroundResource(recyclerItem.getBackgroundcolorResource()); else { final int[] backgroundcolors = Preferences.backgroundSelectorsGrey; holder.itemVIEw.setBackgroundResource(backgroundcolors[position % backgroundcolors.length]); } holder.textMain.setText(recyclerItem.getTextMain()); if (recyclerItem.isImageRightAvailable()) { if (recyclerItem.isProgressBaravailable()) if (recyclerItem.shouldShowDoneImage()) setDrawableFromSVG(holder.imageRight,recyclerItem.getimageRightResourceDone()); else setDrawableFromSVG(holder.imageRight,recyclerItem.getimageRightResource()); } else holder.imageRight.setVisibility(VIEw.GONE); if (recyclerItem.isTextMainBottomAvailable()) holder.textMainBottom.setText(recyclerItem.getTextMainBottom()); else holder.textMainBottom.setVisibility(VIEw.GONE); if (recyclerItem.isTextRighttopAvailable()) holder.textRighttop.setText(recyclerItem.getTextRighttop()); else holder.textRighttop.setVisibility(VIEw.GONE); if (recyclerItem.isTextRightBottomAvailable()) holder.textRightBottom.setText(recyclerItem.getTextRightBottom()); else holder.textRightBottom.setVisibility(VIEw.GONE); if (recyclerItem.isProgressBaravailable()) holder.progressbar.setProgress(recyclerItem.getProgress()); else holder.progressbar.setVisibility(VIEw.GONE); setAnimation(holder.itemVIEw,position); } @OverrIDe public long getItemID(int position) { return List.get(position).hashCode(); } @OverrIDe public int getItemCount() { return List.size(); } private voID setAnimation(VIEw vIEwToAnimate,int position) { if (position > lastposition) { Animation animation = AnimationUtils.loadAnimation(context,R.anim.appear); vIEwToAnimate.startAnimation(animation); lastposition = position; } } public Drawable setDrawableFromSVG(ImageVIEw imageVIEw,int resource) { SVG svg = new SVGBuilder() .readFromresource(context.getResources(),resource) .build(); imageVIEw.setLayerType(VIEw.LAYER_TYPE_SOFTWARE,null); imageVIEw.setimageDrawable(svg.getDrawable()); return svg.getDrawable(); } public final static class ListItemVIEwHolder extends RecyclerVIEw.VIEwHolder implements VIEw.OnClickListener { OnRecyclerVIEwItemClickListener onRecyclerVIEwItemClickListener; TextVIEw textMain,textMainBottom,textRighttop,textRightBottom; ImageVIEw imageRight; Progressbar progressbar; VIEw itemVIEw; public ListItemVIEwHolder(VIEw itemVIEw,OnRecyclerVIEwItemClickListener onRecyclerVIEwItemClickListener,boolean isClickable,int height) { super(itemVIEw); this.itemVIEw = itemVIEw; this.onRecyclerVIEwItemClickListener = onRecyclerVIEwItemClickListener; textMain = (TextVIEw) itemVIEw.findVIEwByID(R.ID.List_item_text_main); imageRight = (ImageVIEw) itemVIEw.findVIEwByID(R.ID.List_item_image_right); textRighttop = (TextVIEw) itemVIEw.findVIEwByID(R.ID.List_item_text_right_top); textRightBottom = (TextVIEw) itemVIEw.findVIEwByID(R.ID.List_item_text_right_bottom); textMainBottom = (TextVIEw) itemVIEw.findVIEwByID(R.ID.List_item_text_main_bottom); progressbar = (Progressbar) itemVIEw.findVIEwByID(R.ID.List_item_progress_bar); switch (height) { case RecyclerItemmodel.HEIGHT_FulL: itemVIEw.setLayoutParams(new relativeLayout.LayoutParams(relativeLayout.LayoutParams.MATCH_PARENT,Preferences.squareLength)); break; case RecyclerItemmodel.HEIGHT_HALF: itemVIEw.setLayoutParams(new relativeLayout.LayoutParams(relativeLayout.LayoutParams.MATCH_PARENT,Preferences.squareLength / 2)); } if (isClickable) itemVIEw.setonClickListener(this); } @OverrIDe public voID onClick(VIEw v) { onRecyclerVIEwItemClickListener.onRecyclerVIEwItemClick(getposition()); } }}解决方法 这是解决我的问题:
动画在某种程度上导致RecyclerVIEw出现问题.所以我的解决方案是删除以下行:
setAnimation(holder.itemVIEw,position);
我没有尝试再次添加动画,但如果你真的需要它,这里有一些有用的东西:How to animate RecyclerView items when they appear.
总结以上是内存溢出为你收集整理的android – 在滚动RecyclerView时发生很奇怪的事情全部内容,希望文章能够帮你解决android – 在滚动RecyclerView时发生很奇怪的事情所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)