softwaresupply
softwaresupply

Reputation: 1948

Layout computation duration is too long

I start an Activity which initializes a complex layout. This is a table, with a lot of images, textviews, EditTexts, Checboxes, Spinners and ActionListeners. The position of each item is different, depending on the callee where it is started. So the information is stored in the Intent.

This means: The layout can not be constructed via XML since all the items always have a different position.

The problem: This computation takes a lot of time. It can take up to 400 ms before the activity can start. This is very bad.

How can I avoid this? As far as I know, I can not precompute the layout. It is not possible to clone views. An if I create that view in another Activity and assign it here, I get some crashes as well.

Upvotes: 2

Views: 125

Answers (2)

QED
QED

Reputation: 9913

Build your layout in pieces and animate it the entire construction for the user. Might take > 400 ms to complete, but the user is gaga for the experience of watching your beautiful layout get created before his eyes. More advice than this is difficult to give without layout details from you.

Upvotes: 1

Bharat Sharma
Bharat Sharma

Reputation: 3966

I also think that 400 ms is not a lot of time.

One more thing you can try is that you can create your layout in xml files and in your activity create a function which reposition all elements. For repositioning first you can get the layout params of your views then you can set new positions and then you can setlayoutparams on your views again according to new position.

Upvotes: 0

Related Questions