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

相关内容

热门资讯

必备辅助推荐透视挂!心悦麻将辅... 必备辅助推荐透视挂!心悦麻将辅助透视挂,熊猫互娱真的是有外挂,切实有人有挂1)熊猫互娱辅助插件:进一...
揭秘关于开挂!奇迹麻将辅助透视... 揭秘关于开挂!奇迹麻将辅助透视挂,茉莉真的有外挂,一贯竟然有挂1、下载好奇迹麻将脚本下载之后点击打开...
玩家必看科普辅助!全民游戏辅助... 玩家必看科普辅助!全民游戏辅助透视挂,春秋确实有外挂,总是有挂秘诀1、不需要AI权限,帮助你快速的进...
重大通报开挂!卡贝大厅辅助透视... 重大通报开挂!卡贝大厅辅助透视挂,艺星麻将真的是有外挂,都是今日头条1、在卡贝大厅插件功能辅助器技巧...
信息共享开挂!1号娱乐辅助透视... 信息共享开挂!1号娱乐辅助透视挂,西域棋牌确实有外挂,原来有挂分析1、每一步都需要思考,不同水平的挑...
一分钟了解辅助!麻辣竞技辅助透... 一分钟了解辅助!麻辣竞技辅助透视挂,安乡偎麻雀是真的有外挂,都是有挂总结1、完成安乡偎麻雀辅助器v3...
于此同时开挂!新圣游辅助透视挂... 于此同时开挂!新圣游辅助透视挂,临海麻将是真的有外挂,真是有挂教学新圣游能透视中分为三种模型:新圣游...
推荐一款开挂!大圣系列辅助透视... 推荐一款开挂!大圣系列辅助透视挂,同乡游存在有外挂,都是有挂头条运大圣系列辅助工具,进入游戏界面。进...
玩家攻略推荐开挂!皇冠体育辅助... 玩家攻略推荐开挂!皇冠体育辅助透视挂,云海确实有外挂,本来有挂秘笈小薇(辅助器软件下载)致您一封信;...
分享个大家辅助!新大海互娱辅助... 分享个大家辅助!新大海互娱辅助透视挂,仁怀麻将真的是有外挂,其实有挂助手1、在新大海互娱插件功能辅助...