不同的中心点旋转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、不需要AI权限,帮助你快速...
热点推荐!微乐四川麻将辅助器脚... 热点推荐!微乐四川麻将辅助器脚本软件,微乐四川麻将其实真的是有辅助器辅助技巧1、首先打开微乐四川麻将...
玩家必看!欢乐茶馆透视脚本软件... 玩家必看!欢乐茶馆透视脚本软件,欢乐茶馆总是存在有透视揭露神器1、每一步都需要思考,不同水平的挑战欢...
来一盘!STA辅助器脚本软件,... 来一盘!STA辅助器脚本软件,STA果然是有辅助器普及脚本1)STA有没有挂:进一步探索STA有辅助...
科技介绍!天天石城麻将开挂脚本... 科技介绍!天天石城麻将开挂脚本软件,天天石城麻将本来真的有开挂揭露工具1、任何天天石城麻将透视是真的...
发现一款!雀友会广东潮汕麻将透... 发现一款!雀友会广东潮汕麻将透视挂脚本软件,雀友会广东潮汕麻将果然有透视挂开挂攻略1)雀友会广东潮汕...
玩家实测!欢乐茶馆辅助脚本软件... 玩家实测!欢乐茶馆辅助脚本软件,欢乐茶馆一直是有辅助关于攻略1、欢乐茶馆公共底牌简单,欢乐茶馆透视插...
实测发现!玩玩四川麻将辅助脚本... 实测发现!玩玩四川麻将辅助脚本软件,玩玩四川麻将其实存在有辅助曝光app1、很好的工具软件,可以解锁...