不同的中心点旋转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、操作简单,...
第3分钟神器!微乐小程序免费黑... 第3分钟神器!微乐小程序免费黑科技,微乐小程序脚本入口(开挂)一直真的是有挂(2026)微乐小程序免...
做出回应!微乐小程序免费黑科技... 做出回应!微乐小程序免费黑科技,微乐家乡辅助app免费(透视)总是有挂(哔哩哔哩)1、微乐小程序免费...
两分钟脚本!微乐小程序免费黑科... 两分钟脚本!微乐小程序免费黑科技,微乐小程序自建房辅助ios(开挂)竟然是有挂(2026)1)微乐小...
第二分钟下载!微乐小程序免费黑... 第二分钟下载!微乐小程序免费黑科技,广西微乐小程序微信辅助器免费(开挂)好像是有挂(2026)1、打...
透视app!微乐小程序免费黑科... 透视app!微乐小程序免费黑科技,微信小程序微乐安徽辅助(透视)竟然真的有挂(哔哩哔哩)1、微信小程...
8分钟下载!微乐小程序免费黑科... 8分钟下载!微乐小程序免费黑科技,微乐智能辅助app(开挂)好像存在有挂(2026)进入游戏-大厅左...
长期以来!微乐小程序黑科技,微... 长期以来!微乐小程序黑科技,微乐自建房免费黑科技下载苹果(透视)竟然有挂(哔哩哔哩)1、任何微乐自建...
第三分钟下载!微乐小程序免费黑... 第三分钟下载!微乐小程序免费黑科技,微乐游戏小程序脚本(开挂)真是是真的挂(2026)1、下载好微乐...
透视肯定!微乐小程序黑科技,微... 透视肯定!微乐小程序黑科技,微乐家乡自建房辅助app(透视)确实真的是有挂(哔哩哔哩)1、打开软件启...