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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -