不同的中心点旋转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脚本... WePoke高级策略深度解析‌;透视私人局!aapoker脚本怎么用,poker红龙辅助,教你攻略(...
透视透视挂!wepoekr底牌... 透视透视挂!wepoekr底牌透视,hhpoker透视下载链接在哪里,玩家必看分享(有挂黑科技)1....
透视有挂!德普之星有没有挂,w... 自定义wepoker透视脚本苹果版系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用...
透视教程!德普之星透视辅助,h... 透视教程!德普之星透视辅助,hhpoker透视方法,一分钟揭秘(有挂规律)1、实时开挂更新:用户可以...
透视好友房!德普之星透视辅助i... 透视好友房!德普之星透视辅助ios,aapoker免费透视脚本,分享教程(从前是真的有挂);(需添加...
透视有挂!智星德州菠萝透视插件... 透视有挂!智星德州菠萝透视插件工具,红龙poker脚本,让我来分享经验(有挂辅助挂)1、完成智星德州...
透视模拟器!智星德州菠萝插件官... 1、透视模拟器!智星德州菠萝插件官网,wepoker黑侠辅助器,大神讲解(一贯真的是有挂);详细教程...
透视辅助!aapoker辅助器... 透视辅助!aapoker辅助器是真的吗,wepoker透视脚本,来一盘(有挂技巧);1、aapoke...
透视脚本!hhpoker开辅助... 透视脚本!hhpoker开辅助软件,wepoker有透视吗,必赢教程(本来是有挂);(需添加指定Q群...
透视工具!aapoker透视脚... 透视工具!aapoker透视脚本下载,wepoker辅助器安装包,必备辅助推荐(有挂了解)一、AI软...