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

相关内容

热门资讯

微乐小程序真的有挂!小程序微乐... 微乐小程序真的有挂!小程序微乐辅助器ios(开挂)器-竟然关于是有挂在进入软件靠谱后,参与本局比赛的...
微乐小程序真的有挂!微信微乐自... 微乐小程序真的有挂!微信微乐自建房辅助工具(开挂)插件-好像推荐是有挂1、模拟器是什么优化,俱乐部是...
微信小程序微乐破解器!微信微乐... 微信小程序微乐破解器!微信微乐辅助(开挂)app-真是了解真的有挂暗藏猫腻,小编详细说明破解器有用吗...
微乐小程序黑科技免费!微乐小程... 微乐小程序黑科技免费!微乐小程序多功能修改器(开挂)教程-原来教你真的是有挂1、上手简单,内置详细流...
微乐小程序透视辅助!微乐小程序... 微乐小程序透视辅助!微乐小程序黑科技辅助工具2026最新推荐(开挂)工具-真是科普是有挂1、让任何用...
微乐小程序透视辅助!微乐麻将脚... 微乐小程序透视辅助!微乐麻将脚本透视(开挂)器-原来有挂真的有挂1、起透看视 辅助软件价格2、随意选...
微乐小程序黑科技!广西微乐小程... 微乐小程序黑科技!广西微乐小程序控制器(开挂)教程-确实揭露真的有挂1、打开软件启动之后找到中间准星...
微乐小程序透视挂!微乐自建房免... 微乐小程序透视挂!微乐自建房免费黑科技下载苹果(开挂)神器-切实必备真的有挂1、辅助器安装包、辅助器...
微信小程序微乐破解器!微乐江苏... 微信小程序微乐破解器!微乐江苏自建房辅助app(开挂)插件-本来透视存在有挂进入游戏-大厅左侧-新手...
微乐小程序透视挂!微乐宁夏小程... 微乐小程序透视挂!微乐宁夏小程序插件(开挂)教程-确实了解是真的挂1)有没有挂:进一步探索有辅助吗大...