【问题标题】:Rotating Android ImageView in API 10 (Without using Animation)在 API 10 中旋转 Android ImageView(不使用动画)
【发布时间】:2012-09-13 21:42:51
【问题描述】:

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

我尝试使用此代码,但 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 的情况下旋转 ImageView,而只在 ImageViewCustom 上覆盖或添加旋转方法?

提前致谢:)

【问题讨论】:

    标签: android imageview


    【解决方案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 是图像视图和方向,位图需要旋转的度数。

    【讨论】:

    • 它只是旋转ImageView的背景,而不是ImageView。
    • 是的,但根据您的需要,它可能是有效的,只是想提供帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-06
    • 2011-05-20
    • 1970-01-01
    相关资源
    最近更新 更多