要实现不同的中心点旋转ImageView,可以通过自定义ImageView来实现。下面是一个示例代码:
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();
}
}
RotateImageView imageView = findViewById(R.id.imageView);
imageView.setCenter(imageView.getWidth() / 2, imageView.getHeight() / 2); // 设置中心点为ImageView的中心
imageView.setRotation(45); // 设置旋转角度为45度
通过设置不同的中心点和旋转角度,即可实现不同的中心点旋转ImageView效果。