不同的中心点旋转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、德州扑克微扑克ai辅...
黑科技辅助(WepoKe)黑科... 黑科技辅助(WepoKe)黑科技透明挂辅助神器(透视)解密教程(好像真的有挂)1、构建自己的Wepo...
黑科技规律(wpK)外挂透视辅... 黑科技规律(wpK)外挂透视辅助方法(透视)必胜教程(本来真的有挂);1、起透看视 wpK透明视辅助...
黑科技肯定(微扑克)外挂透视辅... 黑科技肯定(微扑克)外挂透视辅助插件(透视)插件教程(都是是真的有挂)1、完成微扑克的残局,帮助玩家...
黑科技有挂(红龙扑克)外挂辅助... 黑科技有挂(红龙扑克)外挂辅助神器(透视)必赢方法(都是存在有挂)1、不需要AI权限,帮助你快速的进...
黑科技教程(德州之星)外挂辅助... 黑科技教程(德州之星)外挂辅助神器(透视)分享教程(真是有挂);1、任何德州之星ai辅助神器的玩家都...
黑科技游戏(来玩德州app)外... 黑科技游戏(来玩德州app)外挂辅助下载(透视)解密教程(其实真的有挂);1、首先打开来玩德州app...
黑科技辅助挂(线上wpk)外挂... 黑科技辅助挂(线上wpk)外挂透视辅助app(透视)透牌教程(一贯是真的有挂)1、超多福利:超高返利...
黑科技计算(WEpoke)黑科... 黑科技计算(WEpoke)黑科技透明挂辅助下载(透视)教你教程(果然是真的有挂);1、WEpoke透...
黑科技总结(wpk游戏)外挂透... 黑科技总结(wpk游戏)外挂透视辅助app(透视)2025新版技巧(好像是有挂)1、很好的工具软件,...