Szworny Dziąch Szworny Dziąch - 1 month ago 5x
Android Question

Custom ImageView performace

I created a custom

- it's purpose is to fetch image from internet. It's declaration looks as below:

public class WebImageView extends ImageView {

private String mUrl;

private Bitmap mCachedBitmap;

public String getUrl() { return mUrl; }
public void setUrl(String url) {
mUrl = url;

if (mCachedImage == null) {
new ImageDownloader(this).execute(mUrl);
} else {

public WebImageView(Context context) {

public WebImageView(Context context, AttributeSet attrs) {
super(context, attrs);

public WebImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

public WebImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);

private class ImageDownloader extends AsyncTask<String, Void, Bitmap> {

private final ImageView mView;

public ImageDownloader(ImageView view) {
mView = view;

protected Bitmap doInBackground(String... params) {
String url = params[0];
Bitmap image = null;

try {
InputStream in = new;
image = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error Message", e.getMessage());

return image;

protected void onPostExecute(Bitmap result) {



And it's usage is pretty straightforward:

style="@style/ImageView" />

The above xml is placed inside a
. The problem is that when I scroll (or perform some animation) on my items list it performs horribly bad, meaning that scrolling (or animating) is not smooth. Any advice what can I change here to make it perform better?


Don't build a custom view to do this. Just use Glide image loading library.

ImageView targetImageView = (ImageView) findViewById(;  
String internetUrl = "";


Recyclerview Adapter and Glide - same image every 4-5 rows