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

相关内容

热门资讯

重大通报!哥哥打大a辅助工具靠... 重大通报!哥哥打大a辅助工具靠谱嘛,赣牌圈控制牌型辅助器,详细app(了解有挂)重大通报!哥哥打大a...
盘点一款!雀友会潮汕辅助器,四... 盘点一款!雀友会潮汕辅助器,四川游戏家园通用辅助在,详细插件(有人有挂)1、盘点一款!雀友会潮汕辅助...
玩家必用!乐乐围棋入门辅助,小... 玩家必用!乐乐围棋入门辅助,小程序四川血战辅助,详细软件(有挂细节)小程序四川血战辅助是不是有人用挂...
推荐攻略!新超凡手游辅助,雀友... 推荐攻略!新超凡手游辅助,雀友会广东潮汕辅助有开挂,详细攻略(有挂解惑)1、金币登录送、破产送、升级...
专业讨论!长城互娱辅助,神兽互... 专业讨论!长城互娱辅助,神兽互娱辅助免费,详细工具(有挂透明挂)神兽互娱辅助免费是不是有人用挂微扑克...
推荐一款!四川皮皮辅助,广东雀... 推荐一款!四川皮皮辅助,广东雀神挂件脚本开挂,详细软件(有挂秘笈)1、广东雀神挂件脚本开挂有没有辅助...
必知教程!雀神麻雀科技公司,宝... 必知教程!雀神麻雀科技公司,宝宝游戏辅助,详细挂(有挂教学)1、在雀神麻雀科技公司插件功能辅助器技巧...
如何分辨真伪!圣游科技,四川游... 如何分辨真伪!圣游科技,四川游戏家园通用辅助在,详细插件(有挂规律)四川游戏家园通用辅助在脚本下载中...
一分钟教你!德扑之星插件,途游... 一分钟教你!德扑之星插件,途游辅助器,详细器(讲解有挂)1、德扑之星插件模拟器是什么优化,德扑之星插...
必备教程!wepoker俱乐部... 必备教程!wepoker俱乐部开挂,四川游戏家园辅助软件,详细软件(讲解有挂)1、该软件可以轻松地帮...