c# - Android view object reuse -- prevent old size from showing up when View reappears -


edit: 1 more piece of possibly relevant info: use case in see problem tab switching. is, create view x on tab a, remove when leaving tab a, recycle tab b. that's when problem happens. when need performance gain . . .

i working on performance of android app. i've noticed can speed things reusing view objects of class we'll call mylayout. (it's custom framelayout subclass, doesn't matter. also, not listview related.) is, when i'm done view, rather letting gc ahold of it, put pool. when same activity wants mylayout object, grab 1 pool, if available. indeed speed app. i'm having hard time clearing old size information. result when grab view back, things fine, in cases, new view briefly appears before laid out new size information. happens though set new layoutparams shortly before or after adding view hierarchy (i've tried both ways; neither helps). user sees brief (maybe 100ms) flash of old size, before goes correct size.

i'm wondering if/how can work around this. below, via c#/xamarin, things i've tried, none of help:

when recycling:

//get mylayoutparams, then: mylayoutparams.width = 0; mylayoutparams.height = 0; this.setmeasureddimension(0, 0); this.requestlayout(); 

immediately before or after bringing -- within same event loop adds layout new parent:

// model object has computed desired x, y, width, , height // it's taken account screen size , like; model's sizes // want. framelayout.layoutparams layoutparams = new framelayout.layoutparams (model.width, model.height); layoutparams.leftmargin = model.x; layoutparams.topmargin = model.y;  this.layoutparameters = layoutparams; 

i've tried bringing below, problem still remains:

framelayout.layoutparams layoutparams = . . .  // same layoutparams above parent.addview(viewthatisbeingrecycled, layoutparams); 

edit: per request, of sequences have tried. suffer same problem. basic issue though layoutparams correct, layout not correct actual layout has not happened yet.

recycling time:

attempt a:

this.removefromhierarchy(); // problem width , height retained 

attempt b:

//get mylayoutparams, then: mylayoutparams.width = 0; mylayoutparams.height = 0; this.setmeasureddimension(0, 0); this.requestlayout(); this.removefromhierarchy(); //problem though layout has been requested, not happen.   //android seems decide since view no longer in hierarchy, //it doesn't need actual layout.  width , height //remain, in attempt above. 

when adding view back:

all attempts call 1 of following subroutine sync layoutparams model:

public static void syncexistinglayoutparamstomodel(framelayout.layoutparams layoutparams, model model) {   layoutparams.topmargin = model.x;   layoutparams.leftmargin = model.y;   layoutparams.width = model.width;   layoutparams.height = model.height; }  public static framelayout.layoutparams createlayoutparamsfrommodel(model model) {   framelayout.layoutparams r = new framelayout.layoutparams(model.width, model.height);   r.leftmargin = x;   r.topmargin = y;   return r; } 

attempt a:

newparent.addview(viewthatisbeingrecycled); // layoutparams of view, then: syncexistinglayoutparamstomodel(mylayoutparams, model); 

attempt b: same a, in opposite order:

// layoutparams of view, then: syncexistinglayoutparamstomodel(mylayoutparams, model); newparent.addview(viewthatisbeingrecycled); 

attempt c: same a, fresh layoutparams:

newparent.addview(viewthatisbeingrecycled); framelayout.layoutparams layoutparams = createlayoutparamsfrommodel(model); viewthatisbeingrecycled.layoutparams = layoutparams; 

attempt d: same b, fresh layoutparams:

framelayout.layoutparams layoutparams = createlayoutparamsfrommodel(model); viewthatisbeingrecycled.layoutparams = layoutparams; newparent.addview(viewthatisbeingrecycled); 

attempt e: using addview takes layoutparams argument:

framelayout.layoutparams layoutparams = createlayoutparamsfrommodel(model); newparent.addview(viewthatisbeingrecycled, layoutparams); 

in 5 cases, problem though layoutparams correct, view made visible user before layout adjusts new layoutparams.

as usual, update position/arrangement of view, must invalidate().

don't want give hackish way through still want take @ this post. may possible requestlayout() not causing view's invalidate.

also try adding android:hardwareaccelerated="true" in manifest.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -