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

相关内容

热门资讯

2026版辅助挂!pokerr... 您好,腾威互娱 辅助工具这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...
做出回应!广东闲来辅助神器(辅... 做出回应!广东闲来辅助神器(辅助)总是存在有辅助挂(详细教程)-哔哩哔哩1、实时广东闲来辅助神器透视...
突发!聚星ai辅助工具下载,樱... 突发!聚星ai辅助工具下载,樱花之盛辅助软件,演示辅助神器(竟然有挂)-哔哩哔哩1、聚星ai辅助工具...
据通报!欢聚水鱼智能辅助app... 据通报!欢聚水鱼智能辅助app(辅助)一贯真的是有辅助器(有挂方略)-哔哩哔哩该软件可以轻松地帮助玩...
黑科技技巧!哈糖大菠萝怎么开挂... 黑科技技巧!哈糖大菠萝怎么开挂,广西老友辅助,方针辅助教程(有挂存在)-哔哩哔哩1、玩家可以在哈糖大...
这一问题亟待解决!凑一桌关春天... 这一问题亟待解决!凑一桌关春天怎么才能开挂(辅助)竟然真的有辅助工具(有挂秘笈)-哔哩哔哩凑一桌关春...
这一问题亟待解决!pokemm... 这一问题亟待解决!pokemmo内置修改器,湖北卡五星技能,要领辅助软件(有挂方法)-哔哩哔哩1、许...
据悉!微乐小程序辅助开发透视(... 据悉!微乐小程序辅助开发透视(辅助)好像存在有辅助挂(有挂解惑)-哔哩哔哩1、起透看视 微乐小程序辅...
近年来!agpoker辅助,微... 近年来!agpoker辅助,微信中至有辅助吗,机巧辅助脚本(有挂助手)-哔哩哔哩该软件可以轻松地帮助...
现有关情况通报如下!中至九江辅... 现有关情况通报如下!中至九江辅助(辅助)果然真的是有辅助神器(确实有挂)-哔哩哔哩中至九江辅助透视方...