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


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

查看所有标签

猜你喜欢:

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

RESTful Web Services Cookbook

RESTful Web Services Cookbook

Subbu Allamaraju / Yahoo Press / 2010-3-11 / USD 39.99

While the REST design philosophy has captured the imagination of web and enterprise developers alike, using this approach to develop real web services is no picnic. This cookbook includes more than 10......一起来看看 《RESTful Web Services Cookbook》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器