Y
Y
Yurii Vlasiuk2017-02-13 14:14:31
Java
Yurii Vlasiuk, 2017-02-13 14:14:31

How to draw a rotating line segment on Android?

It is necessary to make a simple application for Android in Java
Essence: It is necessary to draw a segment that will rotate around one of its end points (essentially a clock hand)
I have not come across Android development before, I would like some links where you can read how to draw a line and do what -would it rotate, ready when naturally I don’t wait)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2017-02-13
@forestyura

You write your control inheriting from the View
class. You override its onDraw method in which you draw everything.

public class TimerView extends View {
  @Override
    public void onDraw(Canvas canvas) {
        // Code
    }
}

And use the trigonometric angle formulas for your arrow.
float angle = <angle> * Math.PI / 180;
float cos = (float)Math.cos(angle);
float sin = (float)Math.sin(angle);
canvas.drawLine(center.x + startradius * cos,
                           center.y + startradius * sin,
                           center.x + endradius * cos,
                            center.y + endradius * sin,
                            paint);
// Где <angle> в радианах

D
davidnum95, 2017-02-13
@davidnum95

Draw a segment with canvas, update with a timer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question