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

相关内容

热门资讯

解密透视!hardrock作必... 解密透视!hardrock作必弊!总是是有辅助技巧(了解有挂)-哔哩哔哩1.hardrock作必弊 ...
开挂透视!wepoker透视功... 开挂透视!wepoker透视功能下载,aapoker怎么设置提高好牌几率,办法教程(有挂攻略)-哔哩...
必备透视!拱趴大菠萝辅助神器!... 必备透视!拱趴大菠萝辅助神器!都是是真的有辅助app(有挂细节)-哔哩哔哩;1、拱趴大菠萝辅助神器公...
揭幕透视!aapoker辅助器... 揭幕透视!aapoker辅助器是真的吗,werplan脚本,教程书教程(有挂透明挂)-哔哩哔哩1、a...
曝光透视!拱趴大菠萝万能挂!竟... 曝光透视!拱趴大菠萝万能挂!竟然是真的有辅助软件(发现有挂)-哔哩哔哩拱趴大菠萝万能挂辅助器是一种具...
关于透视!德普之星app安卓版... 关于透视!德普之星app安卓版破解版,哈糖大菠萝有挂吗5个常用方法,办法教程(了解有挂)-哔哩哔哩1...
详细透视!德州透视是真的吗!一... 详细透视!德州透视是真的吗!一直是有辅助技巧(果真有挂)-哔哩哔哩德州透视是真的吗能透视中分为三种模...
辅助透视!wpk俱乐部怎么作必... 辅助透视!wpk俱乐部怎么作必弊,xpoker辅助,模块教程(真是有挂)-哔哩哔哩wpk俱乐部怎么作...
普及透视!德州局透视脚本下载安... 普及透视!德州局透视脚本下载安装最新版本!一贯是有辅助教程(有挂秘籍)-哔哩哔哩1、上手简单,内置详...
普及透视!wepoker辅助工... 普及透视!wepoker辅助工具,hardrock作必弊,项目教程(有挂详情)-哔哩哔哩1、起透看视...