ViewInflate.inflate is VERY SLOW

by Nickname » Thu, 12 Jun 2008 06:06:47 GMT


Sponsored Links
 Hi,

As title, ViewInflate.inflate() takes about 500ms-1sec to inflat an
XML layout file defining a LinearLayout objects containing two
LinearLayout objects each with about 10 Views objects.

With a ListView of 20 entries, each of the same layout, it will take
10-20 seconds to finish layout the entire ListView.

Is there any faster way to achieve it? For example, faster inflate API
or some API to "clone" the first inflated entry to obtain remaining 19
entries?

Thanks for any feedback.

Nick


--~--~---------~--~----~------------~-------~--~----~



ViewInflate.inflate is VERY SLOW

by Mark Murphy » Thu, 12 Jun 2008 06:14:14 GMT


 


When you say 20 entries, do you mean you anticipate 20 lines being 
visible at one time? Or do you mean the list will have 20 total entries, 
of which some subset will be visible at once?

If the latter, you may be able to take advantage of the passed-in View 
convertView parameter to your list adapter's getView() implementation. 
If non-null, this represents a View you already inflated, but whose 
contents need to change to represent the supplied item position. Just 
cast it to the proper View class and update the innards as needed. This 
will cut the inflations down to only as many lines as are visible.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Warescription: All titles, revisions, & ebook formats, just $35/year

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


ViewInflate.inflate is VERY SLOW

by Nickname » Thu, 12 Jun 2008 06:40:57 GMT


 Thanks, Mark.

I do reuse the "convertView parameter" when it is not null.

The parameter is null at the first time when a listview displays, and
it takes long long long time to finish.

Nick.






--~--~---------~--~----~------------~-------~--~----~



ViewInflate.inflate is VERY SLOW

by Romain Guy » Thu, 12 Jun 2008 06:45:02 GMT


 Hi,

XML inflation is slow but on real hardware it is not as slow as you
describe. However, remember you are developing for a cell phone. Even
if inflating your views was fast, having so many views on screen
(you're talking about 20 views per row in a LinearLayout) will impact
layout, drawing, scrolling and memory performance. You should
seriously consider simplifying this XML file and limit the number of
views you need on screen.









-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~



ViewInflate.inflate is VERY SLOW

by Nickname » Thu, 12 Jun 2008 22:43:15 GMT


 Thanks, Romain.

Your suggestion is valid, because only 5 or so of the 20 views will be
on the row at a time and the others will be hidden.

Maybe I should not use ViewInflate.inflate() at all but add those view
that need to be on the row programmatically.

Nick.








--~--~---------~--~----~------------~-------~--~----~



ViewInflate.inflate is VERY SLOW

by Romain Guy » Thu, 12 Jun 2008 23:10:23 GMT


 ou can (and should) use ViewInflate but you could separate your XML
into several pieces. Another solution that I've used successfully for
the Home screen is to write your own layout so as to reduce the number
of Views.

Note that the next SDK will provide several new XML tags to help
reduce the number of views in a layout.

On Wed, Jun 11, 2008 at 4:50 PM, Nickname <[EMAIL PROTECTED]> wrote:



--
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~



ViewInflate.inflate is VERY SLOW

by Nickname » Fri, 13 Jun 2008 23:25:04 GMT


 hanks again, Romain.

It is gear to separate one layout into pieces!

Why didn't I think of it?!!

Nick

On Jun 12, 7:10 am, "Romain Guy" <[EMAIL PROTECTED]> wrote:

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Grayscaling

Hi,

I am trying to grayscale bitmap as follows, But it is crashing as soon
as I run this method.
The problem is in last line. How can I assign "int" to "Color"? Or are
there any better ways? Thx

for(int y = 0; y < imgH; y++)
for(int x = 0; x < imgW; x++)
        {
                int color = bitmap.getPixel(x, y);

                int r = (color >> 16) & 0xff;
                int g = (color >> 8) & 0xff;
                int b = color & 0xff;

                color = Color.rgb(r/3, g/3, b/3);

                bm.setPixel(x, y, color);
        }

--~--~---------~--~----~------------~-------~--~----~

2. Canvas.drawBitmap() src/dst Rect precision

When using Canvas.drawBitmap() with a src and dst Rect, are the edges
considered inclusive?  Presumably the left and top edges are, but I am
unsure about the right and bottom edges.  Consider the following:

Rect src1 = new Rect(0, 0, 0, 0);
Rect dst1 = new Rect(1, 1, 1, 1);
cv.drawBitmap(bm, src1, dst1, null);

Rect src2 = new Rect(0, 0, 1, 1);
Rect dst2 = new Rect(1, 1, 2, 2);
cv.drawBitmap(bm, src2, dst2, null);

Which of the two examples above blits a 1x1 pixel rect from the upper-
left corner of bm to the second row/col pixel of cv?  Presumably, one
of them does.

More to the point, if the right and bottom edges are inclusive, then
the following is an error, correct?:

//Blit lower right subRect to an arbitrary location
Rect src = new Rect(x1, y1, width, height);
Rect dst = new Rect(x2, y2, (width - x1), (height - y1));
cv.drawBitmap(bm, src, dst, null);

If the edges are inclusive those blits read from off the right/bottom
edges of bm and write an extra row/col of pixels on the right/bottom
of the dst rect into cv?  In which case the correct usage would be to
replace width with (width - 1) and likewise for height.

So, which way is correct?  How are the edges of the Rects interpreted?

Thanks.
--~--~---------~--~----~------------~-------~--~----~

3. Control which items to redraw? (notifyDataSetChanged with a range)

4. Android default color madness, primary_text_light is color black?

5. breakpoints and widgets

6. Accessing java SIM card information from android

7. Can we send long SMS message (size > 160 char) and can recieve same in one shot at reciever side?