如何在Android中按百分比缩放ImageView中的图像

时间:2016-10-03 06:02:41

标签: android image

我按照以下方式缩放图像

private class ScaleGestureListener implements ScaleGestureDetector.OnScaleGestureListener {

    @Override
    public boolean onScale(ScaleGestureDetector detector) {
        d = mImageViewMain.getDrawable();
        float offsetX = (mImageViewMain.getWidth() - d.getIntrinsicWidth())/2F;
        float offsetY = (mImageViewMain.getHeight() - d.getIntrinsicHeight())/2F;
        float centerX = mImageViewMain.getWidth()/2F;
        float centerY = mImageViewMain.getHeight()/2F;
        mScale *= detector.getScaleFactor();
        mScale=Math.max(0.1f,Math.min(mScale,5f));
        matrix.setScale(mScale,mScale,centerX,centerY);
        matrix.preTranslate(offsetX,offsetY);
        mImageViewMain.setImageMatrix(matrix);

        return true;
    }

    @Override
    public boolean onScaleBegin(ScaleGestureDetector detector) {
        mScale = 1.0f;
        return true;
    }

    @Override
    public void onScaleEnd(ScaleGestureDetector detector) {
        return;
    }
}

但现在我需要按百分比缩放它。我尝试了太多方法,但仍然无法做到。我怎么能这样做?

0 个答案:

没有答案