imageview - Overlay second image on top of image within ImageViewTouch on Android -
i'm having hard time believing isn't possible. have map in imageviewtouch view, , i'm trying add "you here" image on image move (within map image) based on user's location.
when user pans around on map, i'd here pan being inside imageviewtouch. (ideally i'd scale zooming too, i'll take can get!)
i've considered using canvas create new bitmap every time user's location changes, considering map large, wouldn't performant.
is there way this?
i figured out! instead of using canvas , bitmap slower , cause issues, able use layerdrawable. in case helps in future, here's code.
public void updateyouarehere(@nullable maplocation location, boolean initial){ resources resources = getresources(); drawable drawable; if (location == null){ drawable = miscutil.getdrawable(resources, r.drawable.map_image); }else{ drawable[] layers = new drawable[]{ miscutil.getdrawable(resources, r.drawable.map_image), miscutil.getdrawable(resources, r.drawable.you_are_here) }; mapdrawable = new layerdrawable(layers); final int iconwidth = 50; final int iconheight = 86; mapdrawable.setlayerinset(1, location.x, location.y, (int)(globals.map.mapwidth) - location.x - iconwidth, (int)(globals.map.mapheight) - location.y - iconheight); drawable = mapdrawable; } if (!initial) { matrix currentposition = mapscrollview.getdisplaymatrix(); float minscale = mapscrollview.getminscale(); float maxscale = mapscrollview.getmaxscale(); mapscrollview.setimagedrawable(drawable, currentposition, minscale, maxscale); }else{ mapscrollview.setimagedrawable(drawable); } } private class maplocation { public int x; public int y; public maplocation(int x, int y){ this.x = x; this.y = y; } } also, miscutil.getdrawable wrapper calls appropriate getresources().getdrawable() function based on sdk version.
Comments
Post a Comment