0

我想将 ImageView 旋转到特定的枢轴并具有特殊的度数。我在谷歌中搜索并找到了一些解决方案,但我没有找到关于这个的完整答案(比如这个答案)。

我尝试使用此代码,但ImageView没有旋转!只是它的背景旋转(不旋转视图矩形)

public class ImageViewCustom extends ImageView {
    public Context M_context;

    public ImageViewCustom(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.M_context = context;
    }

    public ImageViewCustom(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.M_context = context;
    }

    public ImageViewCustom(Context context) {
        super(context);
        this.M_context = context;
    }

    public float xPivot;
    public float yPivot;
    public float degree;

    public void draw(Canvas canvas) {
        canvas.save();
        canvas.rotate(degree, xPivot, yPivot);
        super.draw(canvas);
        canvas.restore();
    }
}

那么,如何在不使用Animation并且仅使用覆盖或添加旋转方法的情况下旋转 ImageViewImageViewCustom呢?

提前致谢 :)

4

1 回答 1

-1
Bitmap bmp = arrow.copy(Bitmap.Config.ARGB_8888, true);
Matrix matrix = new Matrix();
matrix.postRotate(direction);
Bitmap bmpRotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),bmp.getHeight(), matrix, true);
iv.setImageBitmap(bmpRotated);

iv 是图像视图和方向,位图需要旋转的度数。

于 2012-09-13T13:42:51.370 回答