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

相关内容

热门资讯

据权威媒体报道!hhpoker... 据权威媒体报道!hhpoker辅助靠谱吗,德扑之星私人局辅助器,原来存在有挂(有挂解惑)1、起透看视...
2026版技巧!wepoker... 2026版技巧!wepoker软件辅助程序,德普之星透视辅助插件,都是是有挂(有挂解惑)1、德普之星...
有了最新消息!hhpoker德... 有了最新消息!hhpoker德州真的假的,德扑之星透视免费,原来存在有挂(有挂神器)1、进入到德扑之...
黑科技教程!德州透视是真的假的... 您好,德扑之星辅助器app这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
据公告内容!we poker辅... 据公告内容!we poker辅助器v3.3,德普辅助软件,真是是真的有挂(有挂方式)1、下载好德普辅...
攻略辅助挂!哈糖大菠萝怎么开挂... 攻略辅助挂!哈糖大菠萝怎么开挂,德扑软件,确实确实有挂(有挂规律)1、进入游戏-大厅左侧-新手福利-...
随着!hhpoker辅助挂是真... 随着!hhpoker辅助挂是真的吗,智星菠萝有挂吗,果然真的是有挂(有挂方略)亲,关键说明,智星菠萝...
近期!wepoker私人局有透... 近期!wepoker私人局有透视吗,德普之星透视辅助软件下载,其实真的有挂(有挂规律)一、德普之星透...
近期!hhpoker是真的假的... 近期!hhpoker是真的假的,德扑之心免费透视,好像是有挂(确实有挂)1)德扑之心免费透视有没有挂...
方法辅助挂!hhpoker的辅... 方法辅助挂!hhpoker的辅助是真的吗,德普之星辅助工具如何设置,好像存在有挂(证实有挂)暗藏猫腻...