Fit to Android Imageview Matrix Center of Screen -
hello im using function fit screen on topic android image view matrix scale + translate
float imagewidth = imagedetail.getdrawable().getintrinsicwidth(); float imageheight = imagedetail.getdrawable().getintrinsicheight(); rectf drawablerect = new rectf(0, 0, imagewidth, imageheight); rectf viewrect = new rectf(0, 0, imagedetail.getwidth(), imagedetail.getheight()); matrix.setrecttorect(drawablerect, viewrect, matrix.scaletofit.center); imagedetail.setimagematrix(matrix); imagedetail.invalidate();
it works not first time. when start application doesnt work. image doesnt show. when m tap works. im wrong? advice
hi should place code in onwindowfocuschanged method.
@override public void onwindowfocuschanged(boolean hasfocus) { super.onwindowfocuschanged(hasfocus); float imagewidth = image.getdrawable().getintrinsicwidth(); float imageheight = image.getdrawable().getintrinsicheight(); rectf drawablerect = new rectf(0, 0, imagewidth, imageheight); rectf viewrect = new rectf(0, 0, image.getwidth(), image.getheight()); matrix matrix = new matrix(); matrix.setrecttorect(drawablerect, viewrect, matrix.scaletofit.center); image.setimagematrix(matrix); image.invalidate(); }
android matrix imageview center
No comments:
Post a Comment