不同的中心点旋转ImageView
创始人
2025-01-08 21:30:38
0

要实现不同的中心点旋转ImageView,可以通过自定义ImageView来实现。下面是一个示例代码:

  1. 创建一个自定义的ImageView类,命名为RotateImageView:
public class RotateImageView extends ImageView {

    private float centerX;
    private float centerY;
    private float rotation;

    public RotateImageView(Context context) {
        super(context);
    }

    public RotateImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RotateImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.rotate(rotation, centerX, centerY);
        super.onDraw(canvas);
    }

    public void setRotation(float rotation) {
        this.rotation = rotation;
        invalidate();
    }

    public void setCenter(float centerX, float centerY) {
        this.centerX = centerX;
        this.centerY = centerY;
        invalidate();
    }
}
  1. 在布局文件中使用RotateImageView:

  1. 在代码中使用RotateImageView并设置不同的中心点和旋转角度:
RotateImageView imageView = findViewById(R.id.imageView);
imageView.setCenter(imageView.getWidth() / 2, imageView.getHeight() / 2); // 设置中心点为ImageView的中心
imageView.setRotation(45); // 设置旋转角度为45度

通过设置不同的中心点和旋转角度,即可实现不同的中心点旋转ImageView效果。

相关内容

热门资讯

突发!pokermaster辅... 突发!pokermaster辅助器,微信大厅辅助挂,窍要辅助神器(今日头条)-哔哩哔哩所有人都在同一...
据权威媒体报道!花花生后圈开挂... 据权威媒体报道!花花生后圈开挂(辅助)切实真的有辅助平台(有挂讲解)-哔哩哔哩1、每一步都需要思考,...
今天上午!拱趴大菠萝挂哪里,w... 今天上午!拱趴大菠萝挂哪里,wepoker修改工具,课程辅助方法(有挂技巧)-哔哩哔哩拱趴大菠萝挂哪...
据悉!九游辅助工具(辅助)竟然... 据悉!九游辅助工具(辅助)竟然是有辅助app(有挂头条)-哔哩哔哩1、实时九游辅助工具透视辅助更新:...
透视挂!xpoker怎么作必弊... 透视挂!xpoker怎么作必弊,新海贝之城万能辅助器,法门辅助技巧(有挂教程)-哔哩哔哩1、首先打开...
此事引发网友热议!微信小程序雀... 此事引发网友热议!微信小程序雀神挂件辅助(辅助)果然是真的辅助插件(详细教程)-哔哩哔哩一、微信小程...
2026版辅助挂!佛手大菠萝1... 2026版辅助挂!佛手大菠萝13道挂哪里,广西八一字牌可以破解吗,诀窍辅助方法(有挂方针)-哔哩哔哩...
现就发布提示!微信大a辅助(辅... 现就发布提示!微信大a辅助(辅助)都是真的是有辅助插件(有挂技巧)-哔哩哔哩1、每一步都需要思考,不...
2026版软件!约局吧德州真的... 2026版软件!约局吧德州真的有透视挂吗,wepoker手机版透视脚本,资料辅助方法(今日头条)-哔...
昨日!皮皮跑子辅助(辅助)一贯... 昨日!皮皮跑子辅助(辅助)一贯有挂辅助软件(有挂分析)-哔哩哔哩1、实时皮皮跑子辅助透视辅助更新:用...