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

相关内容

热门资讯

每日必看教程!微信小程序家乡大... 每日必看教程!微信小程序家乡大二解码(辅助挂)xpoker辅助(最初是真的有挂)是一款可以让一直输的...
一分钟带你了解!四川皮皮辅助(... 一分钟带你了解!四川皮皮辅助(辅助挂)wepoker好友局透视(一向存在有挂);1、让任何用户在无需...
今日百科!闽游辅助软件(辅助挂... 今日百科!闽游辅助软件(辅助挂)佛手在线是不是有挂(确实有挂)是一款可以让一直输的玩家,快速成为一个...
查到实测!四川长牌皮皮游戏挂(... 查到实测!四川长牌皮皮游戏挂(辅助挂)德州透视脚本(一向真的有挂);1、很好的四川长牌皮皮游戏挂工具...
发现一款!微信小程序功夫川辅助... 发现一款!微信小程序功夫川辅助(辅助挂)wepokerplus作弊(原先有挂);1、AI玩家辅助神器...
记者爆料!丽水都来脚本辅助(辅... 记者爆料!丽水都来脚本辅助(辅助挂)智星菠萝有挂吗(原来真的是有挂);1、点击下载安装,丽水都来脚本...
教程攻略!潮汕激k辅助器(辅助... 教程攻略!潮汕激k辅助器(辅助挂)wpk辅助购买(其实有挂);亲真的是有正版授权,小编(透视辅助软件...
玩家必知教程!填大坑辅助视频(... 玩家必知教程!填大坑辅助视频(辅助挂)wepoker辅助器最新版本更新内容(真是是有挂)相信很多朋友...
揭秘!授权二厅辅助(辅助挂)w... 揭秘!授权二厅辅助(辅助挂)wpk俱乐部是真的吗(原先真的是有挂)是一款可以让一直输的玩家,快速成为...
一分钟揭秘!赣湘互娱挂(辅助挂... 一分钟揭秘!赣湘互娱挂(辅助挂)wepoker免费脚本弱密码(果然是有挂);一、wepoker免费脚...