android - Using multiple imageview from one source -
i have 1 imageview in activity_main.xml , i'd draw 2 in different position. tried without succes:
image = (imageview)findviewbyid(r.id.imageview1); image2 = (imageview)findviewbyid(r.id.imageview1); layoutparams params = (linearlayout.layoutparams) image.getlayoutparams(); layoutparams params2 = (linearlayout.layoutparams) image2.getlayoutparams(); params.topmargin = 50; params.leftmargin = 50; image.setlayoutparams(params); params2.topmargin = 100; params2.leftmargin = 100; image2.setlayoutparams(params2); it draws 1 piece. tried setimagebitmap:
image2.setimagebitmap(((bitmapdrawable)image.getdrawable()).getbitmap()); how should solve this?
you seeing 1 imageview because there 1 imageview in layout. both image , image2 reference same id (r.id.imageview1) in layout:
image = (imageview)findviewbyid(r.id.imageview1); image2 = (imageview)findviewbyid(r.id.imageview1); you can solve 2 ways see it:
- inflate
imageviews 1 @ time , add them layout @ runtime. bit more complicated trying do. - add
imageviewxml layout (set idr.id.imageview2) appropriate margins want. reference eachimageviewin code , edit them separately.
solution #2 in code (after adding 2nd imageview xml layout):
image = (imageview)findviewbyid(r.id.imageview1); image2 = (imageview)findviewbyid(r.id.imageview2);
Comments
Post a Comment