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

相关内容

热门资讯

2027版外挂!四川家园外挂多... 2027版外挂!四川家园外挂多功能AIapp,四川家园好像真的是有外挂app1、超多福利:超高返利,...
安装程序教程辅助挂!廊坊麻将鲨... 安装程序教程辅助挂!廊坊麻将鲨鱼互动ai辅助挂多功能插件,确实是有辅助挂软件演示是一款可以让一直输的...
2027版开挂!中至麻将开挂多... 2027版开挂!中至麻将开挂多功能AI攻略,中至麻将确实真的是有开挂攻略1、让任何用户在无需中至麻将...
安装教程透视!邳州麻将ai透视... 安装教程透视!邳州麻将ai透视多功能插件,一向存在有透视教程指南是一款可以让一直输的玩家,快速成为一...
2027版辅助器!天涯麻将辅助... 2027版辅助器!天涯麻将辅助器多功能AI攻略,天涯麻将果然真的有辅助器攻略1、玩家可以在天涯麻将线...
必备辅助推荐透视!同仁娱乐ai... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成同仁娱乐解析、 AI 处理、同仁娱乐...
2027版辅助器!家家盘锦麻将... 2027版辅助器!家家盘锦麻将辅助器多功能AI软件,家家盘锦麻将本来存在有辅助器软件进入游戏-大厅左...
总结教程辅助!良人麻将ai辅助... 很多人使用云端 AI 时,都担心良人麻将、内部资料上传带来隐私风险。这款本地运行的 AI 黑科技,很...
2027版外挂!天天麻将浠水外... 2027版外挂!天天麻将浠水外挂多功能AI教程,天天麻将浠水原来存在有外挂教程1、天天麻将浠水公共底...
一分钟揭秘辅助挂!大巴杭州ai... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...