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

相关内容

热门资讯

黑科技辅助!微乐自建房免费黑科... 黑科技辅助!微乐自建房免费黑科技下载苹果(辅助),微乐够级总是真的是有透视挂方法微乐自建房免费黑科技...
黑科技作弊器!微乐广西小程序开... 黑科技作弊器!微乐广西小程序开挂(作弊器),微乐贵阳捉鸡原来有透视挂插件1、让任何用户在无需微乐广西...
黑科技外挂!小程序微乐辅助软件... 黑科技外挂!小程序微乐辅助软件(外挂),微乐卡五星麻将果然是真的有透视挂技巧1、点击下载安装,小程序...
黑科技作弊器!微乐家乡麻将辅助... 黑科技作弊器!微乐家乡麻将辅助(作弊器),微乐盐城麻将其实真的是有透视挂技巧1、打开软件启动之后找到...
黑科技透视挂!微乐自建房辅助工... 黑科技透视挂!微乐自建房辅助工具别人怎么看(透视挂),微乐安庆麻将好像存在有透视挂教程1、这是跨平台...
黑科技开挂!微乐陕西三代自建房... 黑科技开挂!微乐陕西三代自建房挂(开挂),微乐松原麻将确实有透视挂方法1、微乐陕西三代自建房挂有没有...
黑科技辅助器!微信小程序微乐陕... 黑科技辅助器!微信小程序微乐陕西挖坑(辅助器),微乐齐齐哈尔麻将本来真的有透视挂教程暗藏猫腻,小编详...
黑科技辅助!小程序微乐陕西挖坑... 黑科技辅助!小程序微乐陕西挖坑辅助器(辅助),微乐宝鸡麻将真是真的是有透视挂插件小薇(辅助器软件下载...
黑科技作弊器!微乐自建房辅助工... 黑科技作弊器!微乐自建房辅助工具在哪(作弊器),微乐够级竟然是真的有透视挂app1、每一步都需要思考...
黑科技作弊器!微信小程序游戏辅... 黑科技作弊器!微信小程序游戏辅助(作弊器),微乐邯郸麻将确实存在有透视挂工具1、首先打开微信小程序游...