juell
juell

Reputation: 4960

Android: Knowing ahead of time what size an ImageView will be?

My application uses thumbnails downloaded from the internet. The thumbnails are generated by the server, and one specifies in the request what size the thumbnails should be. Is there a way for me to know, programmatically, while inside a ListAdapter's getView(), the dimensions of an ImageView inside the View that is returned, so my thumbnail comes perfectly scaled? I can always hardcode it, but I'd prefer not to.

Alternatively, is there some sort of listener or callback I can use to request the thumb once the View has been laid out?

EDIT: The ImageViews have fixed layout_height and layout_width, however, I'd want to reuse the same code for different parts of the app, which use different size images, which is why hardcoding is particularly bad.

Upvotes: 1

Views: 216

Answers (1)

matthew
matthew

Reputation: 1

You won't know dimensions at the construction phase of the ImageView in getView. (obviously convertViews are different).

I have gotten round this by creating a subclassed ImageView that implements the View.OnLayoutChangeListener onLayoutChanged method and triggers loading of the image via our resizer proxy (and via a local memcache). Whether this is the most elegant way, I don't know but it works. It all seems ugly compared to iOS!

See also:

Android: Finding size (resolution-wise) of a GalleryView.

Upvotes: 0

Related Questions