android - Getting width of a Custom View -


i need width of custom view i'm creating extending linearlayout. initial stab do

int width = this.getlayoutparams().width 

however, return -1.

next, attempted overriding onmeasure(int, int)

@override protected void onmeasure(int width, int height) {     super.onmeasure(width, height);     this.width = measurespec.getsize(width); } 

this worked width being executed after needed width (i guess view wasn't built yet?)

i need google maps method:`map.movecamera(cameraupdatefactory.newlatlngbounds(bounds, width, height, map_padding));

any suggestions on getting width?

unless explicitly set view's width/height static value (like x-dp or match_parent), cannot know size of view until onmeasure loop completed. android can call onmeasure multiple times find suitable size, it's not best place find exact size. may have find way delay map.movecamera onlayout function.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -