How to rotate EditText manually on Android

I have an image editing application in which I use a custom EditTextView that fits in an ImageView . This image is also a custom view that can rotate, scale, drag, etc. Now, I want to drag this EditText and rotate it when you click on the button. This is my custom EditTextView :

 public class TemplateTextView extends EditText { private static float angle; // We can be in one of these 3 states private int mode = NONE; // Remember some things for zooming PointF start = new PointF(); PointF mid = new PointF(); PointF startMargins = new PointF(); float oldDist = 1f; /** * Constructor for TemplateTextView * * @param context * @param attrs * @param defStyle */ public TemplateTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // mWindowManager = (WindowManager) // context.getSystemService(Context.WINDOW_SERVICE); } /** * Constructor for TemplateTextView * * @param context * @param attrs */ public TemplateTextView(Context context, AttributeSet attrs) { this(context, attrs, 0); } /** * Constructor for TemplateTextView * * @param context */ public TemplateTextView(Context context) { this(context, null); } } 

EditTextView dragged by long clicking on it. How can I rotate and drag this view?

+4
source share
1 answer

To rotate, you can simply do this in the onDraw method of your TemplateTextView:

 @Override protected void onDraw(Canvas canvas) { canvas.rotate(angle, canvas.getClipBounds().right/2, canvas.getClipBounds().bottom/2); super.onDraw(canvas); } 

Cheers dude

+1
source

Source: https://habr.com/ru/post/1437148/


All Articles