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

相关内容

热门资讯

黑科技好牌(WPK透视挂)外挂... 黑科技好牌(WPK透视挂)外挂透明挂辅助助手(软件透明挂)原来真的有挂(有挂方针)-哔哩哔哩1、下载...
黑科技存在(Wepoke后台)... 黑科技存在(Wepoke后台)外挂透明挂辅助ai代打(透明挂黑科技)竟然真的有挂(有挂详情)-哔哩哔...
黑科技总结(wepoke最新)... 黑科技总结(wepoke最新)外挂透明挂辅助助手(透视)竟然真的有挂(有挂秘诀)-哔哩哔哩1、完成w...
黑科技中牌率(WPK漏洞)外挂... 黑科技中牌率(WPK漏洞)外挂透明挂辅助器(透明挂黑科技)一直真的是有挂(有挂秘籍)-哔哩哔哩1、进...
黑科技有挂(Wepoke辅助a... 黑科技有挂(Wepoke辅助ai)外挂透明挂辅助ai代打(辅助挂)切实有挂(有挂秘籍)-哔哩哔哩1、...
黑科技讲解(Wepoke大厅房... 黑科技讲解(Wepoke大厅房)外挂透明挂辅助代打(智能ai)一直真的有挂(有挂细节)-哔哩哔哩1、...
黑科技黑科技(红龙扑克)外挂透... 黑科技黑科技(红龙扑克)外挂透明挂辅助设备(辅助挂)切实真的是有挂(有挂方法)-哔哩哔哩1)红龙扑克...
黑科技规律(wepoke挂)外... 黑科技规律(wepoke挂)外挂透明挂辅助器(ai辅助)本来存在有挂(有挂方针)-哔哩哔哩;1、we...
黑科技玄学(微扑克软件)外挂透... 黑科技玄学(微扑克软件)外挂透明挂辅助挂(透明黑科技)竟然真的有挂(证实有挂)-哔哩哔哩1)微扑克软...
黑科技软件(aapoker开发... 黑科技软件(aapoker开发)外挂透明挂辅助黑科技(ai代打)好像存在有挂(有挂透明挂)-哔哩哔哩...