Created
August 20, 2018 09:27
-
-
Save sujithkanna/9da2235e90dd77e2a5ca16006a3bf98e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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