Skip to content

Instantly share code, notes, and snippets.

@sujithkanna
Created August 20, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujithkanna/9da2235e90dd77e2a5ca16006a3bf98e to your computer and use it in GitHub Desktop.
Save sujithkanna/9da2235e90dd77e2a5ca16006a3bf98e to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
public class RotatableImageView extends android.support.v7.widget.AppCompatImageView {
private float angle = 0f;
public RotatableImageView(Context context) {
super(context);
}
public RotatableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RotatableImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void rotate(float angle) {
this.angle = angle;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
int save = canvas.save();
canvas.rotate(angle, canvas.getWidth() / 2, canvas.getHeight() / 2);
super.onDraw(canvas);
canvas.restoreToCount(save);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment