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

相关内容

热门资讯

黑科技软件(Wepoke轻量版... 线上德州赢率提升策略‌;黑科技软件(Wepoke轻量版)线上德州好像真的有挂!太无语了其实真的有挂(...
黑科技工具(wepoke好友)... 黑科技工具(wepoke好友)WpK固有有挂!太实锤了竟然是真的有挂(2023已更新)(哔哩哔哩)1...
黑科技规律(wepoke挂透视... 黑科技规律(wepoke挂透视)we-poker其实真的有挂!太无语了原本存在有挂(2020已更新)...
黑科技ai代打(WPK内置)a... WePoker透视辅助版本解析‌,黑科技ai代打(WPK内置)aapOKER真是真的是有挂!太坑了从...
黑科技能赢(德扑线上)微扑克插... 1、黑科技能赢(德扑线上)微扑克插件本然真的是有挂!太坑了切实真的是有挂(2020已更新)(哔哩哔哩...
黑科技好友房(WPK控制)好运... 黑科技好友房(WPK控制)好运大菠萝一向是有挂!太无语了从来真的是有挂(2021已更新)(哔哩哔哩)...
黑科技科技(德扑胜率计算)德州... 黑科技科技(德扑胜率计算)德州俱乐部原先是真的有挂!太实锤了起初真的是有挂(2022已更新)(哔哩哔...
黑科技讲解(wpk辅助挂)wp... 黑科技讲解(wpk辅助挂)wpk微扑克原来真的有挂!太坑了素来真的是有挂(2022已更新)(哔哩哔哩...
黑科技攻略(WPK计算器)po... 此外,数据分析德州(pokenow)辅助神器app还具备辅助透视行为开挂功能,通过对客户pokeno...
黑科技教学(WPK私人房)aa... 黑科技教学(WPK私人房)aapokER原生存在有挂!太离谱了都是有挂(2020已更新)(哔哩哔哩)...