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

相关内容

热门资讯

总算了解!epoker免费透视... 总算了解!epoker免费透视脚本,wepoker网页版透视方法,软件教程(有挂软件);支持2-10...
实测交流!wepoker的辅助... 实测交流!wepoker的辅助器,uupoker透视,普及教程(有挂软件);wepoker的辅助器软...
我来教大家!aa poker辅... 我来教大家!aa poker辅助,拱趴大菠萝作弊方法,新2025教程(有挂技巧);1分钟了解详细教程...
大家学习交流!wepoker辅... 大家学习交流!wepoker辅助真的假的,aapoker怎么设置提高好牌几率,必备教程(有挂教程)这...
关于!wepoker私人局辅助... 1、关于!wepoker私人局辅助,红龙poker辅助平台,安装教程(有挂攻略);详细教程。2、红龙...
推荐十款!pokemmo辅助官... 推荐十款!pokemmo辅助官网,约局吧辅助器,2025新版技巧(有挂教程);大神普及一款德州ai内...
传递经验!wepoker透视脚... 此外,数据分析德州(wepoker透视脚本免费app)辅助神器app还具备辅助透视行为开挂功能,通过...
一分钟了解!wepoker俱乐... 一分钟了解!wepoker俱乐部辅助,wepoker透视脚本免费app,2025新版教程(有挂神器)...
最新技巧!aa poker透视... 1、最新技巧!aa poker透视软件,hhpoker辅助挂,AI教程(有挂软件);详细教程。2、a...
重大通报!werplan怎么作... 您好,wepoker辅助器软件下载这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302...