8

我创建了一个图片库,一切正常。需要放大和移动图像

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);

但不工作。

任何的想法?很抱歉没有插入图片,但我不能因为我的声誉。非常感谢您提前

4

2 回答 2

15

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

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);

希望有人帮助,非常感谢您的回答。

于 2013-01-22T11:29:30.367 回答
4
@Override
public void onWindowFocusChanged(boolean hasFocus) {

    super.onWindowFocusChanged(hasFocus);

    screenWidth = layout.getWidth();
    screenHeight = layout.getHeight();

    Log.e("", "Image Width : " + imageWidth + " > " + imageHeight);
    Log.e("", "screen Width : " + screenWidth + " > " + screenHeight);

    RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight);
    RectF viewRect = new RectF(0, 0, screenWidth, screenHeight);
    matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
    img.setImageMatrix(matrix);
}
于 2014-04-08T10:38:59.623 回答