For example, there is a list in which item s have text fields and n-th number of pictures. What am I doing:
1) I use the ImageLoader library
In the Application class, I initialize it as follows.
public static void initImageLoader(Context context) { DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(null) .cacheInMemory(false) .cacheOnDisk(true) .considerExifParams(true) .showStubImage(R.drawable.place_holder_view_white) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .tasksProcessingOrder(QueueProcessingType.LIFO) .diskCacheSize(50 * 1024 * 1024) .tasksProcessingOrder(QueueProcessingType.LIFO) .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .defaultDisplayImageOptions(options) .build(); ImageLoader.getInstance().init(config); } Where .showStubImage(R.drawable.place_holder_view_white) picture until a loaded picchi appears. This is just a white png-box, with specific dimensions. In the project she is alone.
2) In the adapter, I invoke the boot method, which is:
ImageLoader.getInstance().displayImage(url, imageView, new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { ImageLoader.getInstance().displayImage("drawable://" + R.drawable.icon_image_holder, imageView); ObjectAnimator.ofFloat(imageView, "alpha", 0, 1).setDuration(400).start(); } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { ObjectAnimator.ofFloat(imageView, "alpha", 0, 1).setDuration(400).start(); } @Override public void onLoadingCancelled(String imageUri, View view) { } }); Here you can see that if the picture is not loaded, then it is replaced with another one taken from the project. And if it is loaded, it is smoothly displayed on the place of the stub, through aplha animation.
Everything works fine, but! only if all the pictures have the same size, which coincides with the size of the stub picture. Otherwise, the list starts to twitch. How to make imageHolder automatically adjust to the future size of the inserted image?