1

I need to calculate the measured height of my views without measuring all views, because these views contain images fetched from the internet. When I measure the views, they download images to memory and I an catch out of memory exception. I use custom ScrollViews, which work like ListViews, display some part of views and when scroll, add to bottom or top.

How can I calculate the height of all my views without throwing out of memory exceptions?

Or how can I make ListView calculate its height before rendering views?

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
RomaTTi
  • 327
  • 2
  • 12
  • 1
    I can't work out what's being asked here sorry. – fredley Jan 19 '11 at 12:18
  • I have scrollview (using listview not approach for my task). And i have many childs view. this childsviews add and remove in runtime. I need to now all views height before they rended. And set summ of this heights to scroll range of scrollview. – RomaTTi Jan 19 '11 at 13:01
  • You have asked two questions. 1) You can measure images without loading them into memory by using BitmapFactory and decodingBounds only (see http://stackoverflow.com/questions/2641726/decoding-bitmaps-in-android-with-the-right-size) and then some custom logic your side could work out what size they will be scaled to when placed in your view hierarcy. To answer 2) Re: calc height of views before rendering see http://stackoverflow.com/a/8403680/236743 – Dori Dec 06 '11 at 17:03

2 Answers2

0

You can use getLeft(), getTop(), getRight() and getBottom() these method's on view. for more information . see following link http://developer.android.com/reference/android/view/View.html

Vivek
  • 4,170
  • 6
  • 36
  • 50
0

You answered your own question:

display some part of views and when scroll, add to bottom or top.

ListView does NOT know the heights of items it has not yet seen. It lays out some or all of the items it knows, adds an extra bit of UI at top and bottom to visually indicate that there may be more items, and scrolls that. The total scrollable range for ListView can change as it adds more items.

cdhabecker
  • 1,693
  • 1
  • 14
  • 23