Kev*_*vie 2 java android visibility android-view android-recyclerview
我有一个基本上所有在一个布局,其中包含我的应用程序的主要所需的一切.所有可变项目(图像,视频缩略图等等)GONE首先设置为VISIBLE并在需要时设置为.
问题有时可能是由于RecyclerView回收行为,应该GONE是VISIBLE错误的地方.
示例:
项目编号1包含文本
第2项包含图像
第3项包含图像
我继续向下滚动到项目no x,然后向上滚动,这是我得到的:
项目编号1包含项目编号x的图像,有时编号项目编号3
第2项包含图像
第3项包含图像
我正在使用自定义的ViewHolder extends RecyclerView.ViewHolder.的目的CustomViewHolder是为布局声明和初始化.
ProgressBar progressBar;
View viewDimmer;
RelativeLayout postListWrapper;
...
public ObjectViewHolder(View v) {
super(v);
progressBar = (ProgressBar)v.findViewById(R.id.post_inscroll_progressBar);
viewDimmer = (View)v.findViewById(R.id.post_inscroll_viewDimmer);
postListWrapper = (RelativeLayout)v.findViewById(R.id.post_inscroll_postListWrapper);
}
Run Code Online (Sandbox Code Playgroud)
我如何加载图像的示例:
Picasso.with(context)
.load(youtubeThumbnailUrl)
.fit()
.centerCrop()
.into(
((ObjectViewHolder) holder).userPostYoutubeImage
);
Run Code Online (Sandbox Code Playgroud)
GONE如果没有从服务器获取url,我已将每个可见性设置为
((ObjectViewHolder) holder).userPostImageWrapper.setVisibility(View.GONE);
((ObjectViewHolder) holder).userPostYoutubeImageWrapper.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
但不知何故,图像仍然在之前的项目上重复使用(是的,不仅仅是第1项).有时图像也是错误的ImageView.图像D应该在ImageViewD中,但它在ImageViewA中.
设置RecyclerView和运行良好的指南?
如果我遗漏任何内容,或者需要提供更多代码,请告知我:D
你也需要把else条件.像下面的例子.
// if no url is found from server
if(url == null){
((ObjectViewHolder) holder).userPostImageWrapper.setVisibility(View.GONE);
((ObjectViewHolder) holder).userPostYoutubeImageWrapper.setVisibility(View.GONE);
} else {
// Some url has found
((ObjectViewHolder) holder).userPostImageWrapper.setVisibility(View.VISIBLE);
((ObjectViewHolder) holder).userPostYoutubeImageWrapper.setVisibility(View.VISIBLE);
}
Run Code Online (Sandbox Code Playgroud)
如果您在运行时设置了它们的可见性,请为列表中的每个项目执行此操作.
| 归档时间: |
|
| 查看次数: |
1691 次 |
| 最近记录: |