不同的中心点旋转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、超多福利:超高返...
信息共享!德州wepower透... 信息共享!德州wepower透视辅助,wepoke真的有挂,实用技巧(原先存在有挂)1、不需要AI权...
实操分享!德扑之星怎么带出记分... 实操分享!德扑之星怎么带出记分牌,智星德州菠萝外挂,揭秘攻略(原生是有挂);人气非常高,ai更新快且...
盘点一款!云扑克辅助挂,aa扑... 盘点一款!云扑克辅助挂,aa扑克辅助,2025新版技巧(原来是真的有挂)1、aa扑克辅助ai机器人多...
技巧知识分享!来玩app德州辅... 技巧知识分享!来玩app德州辅助器,wepoke是真的有挂,攻略教程(其实是有挂)是一款可以让一直输...
盘点十款!德州nzt软件,we... 盘点十款!德州nzt软件,wepoke真的有挂,新2025教程(真是是真的有挂)(1)盘点十款!德州...
六分钟了解!鱼扑克软件辅助,w... 六分钟了解!鱼扑克软件辅助,wpk外挂,黑科技教程(本来存在有挂);无聊就玩这款wpk外挂真的有辅助...
终于知道!欢乐棋牌有外挂吗,智... 终于知道!欢乐棋牌有外挂吗,智星德州菠萝,2025教程(最初真的有挂)(1)终于知道!欢乐棋牌有外挂...
安装程序教程!德州ai辅助神器... 安装程序教程!德州ai辅助神器,微扑克辅助挂,AI教程(本然是真的有挂);是一款可以让一直输的玩家,...
科普!wepoke有规律吗,智... 科普!wepoke有规律吗,智星德州菠萝偷偷看牌功能,教你教程(从前真的是有挂);人气非常高,ai更...