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

相关内容

热门资讯

一分钟了解!we-poker是... 一分钟了解!we-poker是什么软件(辅助挂)竟然真的有挂(有挂教程)1、we-poker是什么软...
重大通报!wepoker辅助器... 重大通报!wepoker辅助器软件下载(辅助挂)好像有挂(有挂方针)1、上手简单,内置详细流程视频教...
科普常识!德州透视脚本(辅助挂... 科普常识!德州透视脚本(辅助挂)都是真的有挂(有挂存在)1、德州透视脚本辅助器安装包、德州透视脚本辅...
解密关于!安装不了wepoke... 解密关于!安装不了wepoker(辅助挂)一直是有挂(确实有挂)1、完成安装不了wepoker有辅助...
推荐一款!如何下载wepoke... 推荐一款!如何下载wepoker安装包(辅助挂)一直真的有挂(有挂神器)1、操作简单,无需如何下载w...
实操分享!智星菠萝辅助(辅助挂... 实操分享!智星菠萝辅助(辅助挂)都是是有挂(有挂透明挂)1、许多玩家不知道智星菠萝辅助辅助怎么退出观...
玩家攻略!wepoker软件安... 玩家攻略!wepoker软件安装包(辅助挂)果然是有挂(有挂解惑)1)wepoker软件安装包免费钻...
大神推荐!德普之星怎么开辅助(... 大神推荐!德普之星怎么开辅助(辅助挂)一直是真的有挂(存在有挂)大神推荐!德普之星怎么开辅助(辅助挂...
科普攻略!来玩app破解版(辅... 科普攻略!来玩app破解版(辅助挂)本来存在有挂(竟然有挂)1、来玩app破解版有没有辅助教程、来玩...
重大通报!aapoker能控制... 重大通报!aapoker能控制牌吗(辅助挂)本来存在有挂(真是有挂)1.aapoker能控制牌吗 选...