[android-developers] Can onMeasure be skipped when adding a View to a ViewGroup?

2011-06-09 Thread Kelly Merrell
I have a RelativeLayout where I am adding views dynamically as the
user scrolls vertically or horizontally. I have rolled my own
ViewRecycler since there is potentially thousands of views that could
compose the whole of what can be scrolled, but I only show 30 or so at
any time. Think a zoomed in view of a calendar.

I am running into performance problems when I add the views that are
about to be seen, onMeasure is called on the RelativeLayout cascading
down to onMeasure getting called on all of it's child views. I already
have the calculated size of how big the RelativeLayout will ever be
and have set that on it's LayoutParameters, so measuring the ViewGroup
isn't necessary, nor is re-measuring the Views that have already been
added with their final size and the newly added view has no bearing on
those views.

Is there a recommended way to bypass these onMeasure calls or at least
onMeasure calling measureChildren?

Also posted this on stackoverflow with example code to demonstrate the
undesired behavior: 
http://stackoverflow.com/questions/6298827/can-onmeasure-be-skipped-when-adding-a-view-to-a-viewgroup

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Can onMeasure be skipped when adding a View to a ViewGroup?

2011-06-09 Thread Dianne Hackborn
You will need to write your own layout manager.

On Thu, Jun 9, 2011 at 1:34 PM, Kelly Merrell 
kmerr...@mercuryintermedia.com wrote:

 I have a RelativeLayout where I am adding views dynamically as the
 user scrolls vertically or horizontally. I have rolled my own
 ViewRecycler since there is potentially thousands of views that could
 compose the whole of what can be scrolled, but I only show 30 or so at
 any time. Think a zoomed in view of a calendar.

 I am running into performance problems when I add the views that are
 about to be seen, onMeasure is called on the RelativeLayout cascading
 down to onMeasure getting called on all of it's child views. I already
 have the calculated size of how big the RelativeLayout will ever be
 and have set that on it's LayoutParameters, so measuring the ViewGroup
 isn't necessary, nor is re-measuring the Views that have already been
 added with their final size and the newly added view has no bearing on
 those views.

 Is there a recommended way to bypass these onMeasure calls or at least
 onMeasure calling measureChildren?

 Also posted this on stackoverflow with example code to demonstrate the
 undesired behavior:
 http://stackoverflow.com/questions/6298827/can-onmeasure-be-skipped-when-adding-a-view-to-a-viewgroup

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en