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

相关内容

热门资讯

每日必看推荐!赣牌圈破解器,w... 您好,赣牌圈破解器这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款...
实测交流!填大坑辅助器攻略,红... 实测交流!填大坑辅助器攻略,红龙poker有辅助吗,新版2025教程(有挂分析);1、让任何用户在无...
今日科普!佛手大菠萝破解版io... 今日科普!佛手大菠萝破解版ios,wepoker辅助软件价格,技巧教程(有挂神器);小薇(透视辅助)...
大家学习交流!微信小程序填大坑... 您好,微信小程序填大坑辅助器这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
揭秘几款!丽水都莱大菠萝脚本辅... 揭秘几款!丽水都莱大菠萝脚本辅助,wepoker破解是真的还是假的,透牌教程(有挂功能);丽水都莱大...
玩家亲测!新道游正版作弊,we... 玩家亲测!新道游正版作弊,wepoker辅助是真的假的,透明挂教程(真的有挂)是一款可以让一直输的玩...
实测揭晓!随意玩辅助器,epo... 实测揭晓!随意玩辅助器,epoker有透视吗,分享教程(有挂讲解);随意玩辅助器最新版本免费下载安装...
盘点一款!朋朋政和辅助,大菠萝... 您好:朋朋政和辅助这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
总算了解!多乐找刺激辅助,aa... 总算了解!多乐找刺激辅助,aapoker怎么开辅助器,AI教程(果真有挂);AI辅助机器人普及解说快...
重大消息!海米大厅辅助,aap... 重大消息!海米大厅辅助,aapoker怎么拿好牌,微扑克教程(详细教程);1、点击下载安装,海米大厅...