android – 将矩阵图像定位在imageview的中心

栏目: Android · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/14445606/positioning-an-matrix-image-at-the-center-of-imageview

我创建了一个图像库,一切正常.要放大并移动图像是必需的

ImgView.setScaleType (ImageView.ScaleType.MATRIX)

当我这样做时,我得到的图像很小,所以我称之为方法

scaleFactor = view.getWidth()/(float)view.getDrawable().getIntrinsicWidth();
 matrix.setScale(scaleFactor, scaleFactor);

所以不要错过图像大小,但正如您所看到的,图像高于一切,需要保持在屏幕的中心.

我试过这个

matrix.postTranslate((screen_width-image_width)/2, (screen_height-image_height)/2);

但是不行.

任何的想法?很抱歉没有插入图片,但我不能因为我的声誉.

非常感谢你提前

好的,我已经纠正了错误,只需要输入以下代码行:

RectF drawableRect = new RectF(0, 0, image_width, image_height);
RectF viewRect = new RectF(0, 0, screen_width, screen_height);
matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);

希望有人帮忙,非常感谢你的回答.

翻译自:https://stackoverflow.com/questions/14445606/positioning-an-matrix-image-at-the-center-of-imageview


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

R Cookbook

R Cookbook

Paul Teetor / O'Reilly Media / 2011-3-22 / USD 39.99

With more than 200 practical recipes, this book helps you perform data analysis with R quickly and efficiently. The R language provides everything you need to do statistical work, but its structure ca......一起来看看 《R Cookbook》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具