我有什么
我有GridLayoutManager (RecyclerView)
位置0,2,5,7 已修复自定义图像(相对布局已转换为位图)&休息位置充满服务器图像
我的问题
当我滚动布局中的项目时,更改其位置
我的代码
@Override
public void onBindViewHolder(ProfilePhotosViewHolder ProfilePhotosViewHolder, final int position) {
model = list.get(position);
if (position == 0 || position == 2 || position == 5 || position == 7) {
if (position == 0) {
ProfilePhotosViewHolder.relativeBucket.setVisibility(View.VISIBLE);
ProfilePhotosViewHolder.relativeBucket.setDrawingCacheEnabled(true);
ProfilePhotosViewHolder.relativeBucket.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
ProfilePhotosViewHolder.relativeBucket.layout(0, 0, ProfilePhotosViewHolder.relativeBucket.getMeasuredWidth(), ProfilePhotosViewHolder.relativeBucket.getMeasuredHeight());
ProfilePhotosViewHolder.relativeBucket.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(ProfilePhotosViewHolder.relativeBucket.getDrawingCache());
ProfilePhotosViewHolder.relativeBucket.setDrawingCacheEnabled(false);
ProfilePhotosViewHolder.imgProfilePhotos.setImageBitmap(b);
}
if (position == 2) {
ProfilePhotosViewHolder.relativeFollowers.setVisibility(View.VISIBLE);
......
}
if (position == 5) {
ProfilePhotosViewHolder.relativeFollowing.setVisibility(View.VISIBLE);
......
}
if (position == 7) {
ProfilePhotosViewHolder.relativePosts.setVisibility(View.VISIBLE);
......
}
} else {
ProfilePhotosViewHolder.relativeBucket.setVisibility(View.GONE);
ProfilePhotosViewHolder.relativeFollowers.setVisibility(View.GONE);
ProfilePhotosViewHolder.relativeFollowing.setVisibility(View.GONE);
ProfilePhotosViewHolder.relativePosts.setVisibility(View.GONE);
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
ProfilePhotosViewHolder.imgProfilePhotos.setImageUrl(model.ImagesUri, imageLoader);
ProfilePhotosViewHolder.imgProfilePhotos.setDefaultImageResId(R.drawable.im_profile_monuments);
ProfilePhotosViewHolder.imgProfilePhotos.setErrorImageResId(R.drawable.im_profile_monuments);
}
答案 0 :(得分:4)
这是因为回收机制,在您使用可见性时,您还需要处理每个View
中其他if
的可见性阻止。
例如,对于位置2:
if (position == 2) {
ProfilePhotosViewHolder.relativeFollowers.setVisibility(View.VISIBLE);
ProfilePhotosViewHolder.relativeBucket.setVisibility(View.GONE);
ProfilePhotosViewHolder.relativeFollowing.setVisibility(View.GONE);
ProfilePhotosViewHolder.relativePosts.setVisibility(View.GONE);
}
PS:我建议您使用switch(position)
代替嵌套if
块。