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

相关内容

热门资讯

透视演示!wpk透视辅助下载,... 透视演示!wpk透视辅助下载,wpk辅助(透视)切实真的是有透视方法(哔哩哔哩)亲,关键说明,wpk...
透视法子!wpk免费辅助,wp... 透视法子!wpk免费辅助,wpk插件(透视)真是真的是有脚本软件(哔哩哔哩)1、完成wpk免费辅助有...
透视课程!wepoker透视挂... 透视课程!wepoker透视挂底牌,淘宝买wepoker透视有用吗(透视)果然有透视教程(哔哩哔哩)...
透视法门!拱趴大菠萝挂,pok... 透视法门!拱趴大菠萝挂,pokerworld软件(透视)好像真的是有透视脚本(哔哩哔哩)1、超多福利...
透视机巧!epoker底牌透视... 透视机巧!epoker底牌透视,cloudpoker怎么开挂(透视)都是存在有透视插件(哔哩哔哩)1...
透视练习!德普之星怎么设置埋牌... 透视练习!德普之星怎么设置埋牌,德普之星透视辅助软件(透视)确实有脚本方法(哔哩哔哩)1、让任何用户...
透视技法!wepoker怎么提... 透视技法!wepoker怎么提高运气,we poker辅助器下载(透视)竟然有脚本挂(哔哩哔哩)一、...
透视学习!hhpoker有没有... 透视学习!hhpoker有没有作必弊辅助,hh poker辅助器先试用(透视)竟然是有透视脚本(哔哩...
透视法子!德扑圈透视,德普之星... 透视法子!德扑圈透视,德普之星透视免费(透视)原来是真的透视工具(哔哩哔哩)1、德普之星透视免费公共...
透视经验!wepoker轻量版... 透视经验!wepoker轻量版透视方法,wepoker私人局规律(透视)一直是真的透视技巧(哔哩哔哩...