ImageView imageView = findViewById(R.id.image_view);
Matrix matrix = new Matrix();
private void scaleCanvas(float offset) {
// 计算缩放比例
float scale = 1 - Math.abs(offset) / 100f;
// 设置缩放和偏移
matrix.reset();
matrix.setScale(scale, scale, imageView.getWidth() / 2f, imageView.getHeight() / 2f);
matrix.postTranslate(offset, 0);
// 应用变换矩阵
imageView.setImageMatrix(matrix);
}
// 示例:向右偏移100像素
scaleCanvas(100);
这样,ImageView将会按照计算得到的缩放比例进行缩放,并以偏移量进行偏移。你可以根据实际需求调整缩放比例和偏移量的计算方法。