不同的中心点旋转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效果。

相关内容

热门资讯

了解透视!佛手大菠萝有挂吗,微... 了解透视!佛手大菠萝有挂吗,微乐自建房辅助入口官网,经验教程(有挂方针)-哔哩哔哩进入游戏-大厅左侧...
解密透视!来玩app 德州 辅... 解密透视!来玩app 德州 辅助!一直一直都是有辅助工具(有挂透明挂)-哔哩哔哩1、该软件可以轻松地...
曝光透视!werplan辅助软... 曝光透视!werplan辅助软件!好像是真的有辅助技巧(有挂解惑)-哔哩哔哩暗藏猫腻,小编详细说明w...
分享透视!wepoker作弊视... 分享透视!wepoker作弊视频,微乐自建房辅助软件功能,模块教程(有挂工具)-哔哩哔哩1、wepo...
普及透视!德州圈脚本!切实一直... 普及透视!德州圈脚本!切实一直都是有辅助神器(真是有挂)-哔哩哔哩一、德州圈脚本可以开透视的定义与意...
曝光透视!pokermaste... 曝光透视!pokermaster辅助器,微信小程序辅助多少钱,指南教程(真是有挂)-哔哩哔哩1、首先...
开挂透视!pokemmo脚本辅... 开挂透视!pokemmo脚本辅助器!真是存在有辅助教程(真是有挂)-哔哩哔哩1)pokemmo脚本辅...
专业透视!wepoker辅助真... 专业透视!wepoker辅助真的假的,微信小程序微乐辅助器贴吧,手段教程(讲解有挂)-哔哩哔哩1)w...
揭露透视!佛手在线大菠萝技巧!... 揭露透视!佛手在线大菠萝技巧!确实真的是有辅助攻略(有挂教程)-哔哩哔哩1、上手简单,内置详细流程视...
解密透视!如何下载wepoke... 解密透视!如何下载wepoker安装包,微乐广西小程序,教材教程(有挂透明挂)-哔哩哔哩1、超多福利...