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

相关内容

热门资讯

透视开挂!aapoker透视插... 透视开挂!aapoker透视插件,aapoker真的假的(透视)一直是有挂(哔哩哔哩)1、免费脚本咨...
透视教程书!hhpoker外g... 透视教程书!hhpoker外g挂靠谱吗,HHpoker透视器切实真的有工具,九分钟教程(真实有挂)1...
透视技法!德普之星透视软件免费... 透视技法!德普之星透视软件免费入口官网,德普之星下载原来存在有开挂,第九分钟教程(真的有挂)1、全新...
透视方案!德普之星透视辅助软件... 透视方案!德普之星透视辅助软件是真的吗,德普之星安卓版总是真的是有神器,四分钟教程(果真有挂)1.德...
透视经验!wpk透视辅助方法,... 透视经验!wpk透视辅助方法,WPK靠谱总是真的是有神器,第7分钟教程(有挂分享)1、许多玩家不知道...
透视绝活儿!pokemmo脚本... 透视绝活儿!pokemmo脚本手机版,WePoKer助手确实存在有透视,十分钟教程(真是有挂)1、p...
透视手段!德扑圈透视挂,德扑之... 透视手段!德扑圈透视挂,德扑之心透视好像存在有下载,1分钟教程(揭秘有挂)1、全新机制【德扑圈透视挂...
透视法门!黑侠破解wepoke... 透视法门!黑侠破解wepoker,WePoKer程序一直真的有工具,第二分钟教程(有挂透明挂)所有人...
透视妙招!德州局HHpoker... 透视妙招!德州局HHpoker透视脚本,HHpoker德州局总是是有下载,九分钟教程(了解有挂)亲,...
透视要领!hhpoker是正规... 透视要领!hhpoker是正规的吗,HHpoker脚本挂原来真的有安装,十分钟教程(有挂功能)1、玩...