Question

I have GridView with custom BaseAdapter, because I need my own layout. Each cell has ImageView and TextView. In getView() Method I can set images and text. Problem is Choregrapher tells me, there are too many frames skipped, which means, there is too much work on main thread.

Skipped 172 frames! The Application may be doing too much work on it's main thread.

So I went to official developer sites and found this: http://developer.android.com/training/displaying-bitmaps/index.html

The first lesson shows how to resize images. Ok, now I can resize the images how I need, but I don't know the width and height. So I tried methods like ImageView.getHeight() and ImageView.getWidht() but both methods returned null.

I searched on this Stackoverflow and found, that if I subclass the ImageView, I can get width and height.

@Override
protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld){
        super.onSizeChanged(xNew, yNew, xOld, yOld);
        viewWidth = xNew;
        viewHeight = yNew; 
}

Now I can have these values but problem is I don't know, how to send them to my BaseAdapter. That is my first problem.

The 2nd is how to resize the Images without blocking the main thread. I can't somehow understand the examples on official sites. Any help is appreciated, thank you. :-)

Was it helpful?

Solution

Simple Answer: Use Glide. It loads your Images in the Background and fits them automatically in the ImageView. It is also optimized for fast scrolling so I can only recommend it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top