How to create a needle widget GUI widget in Android?

I need a graphic needle pointer (like a speedometer, etc.) for my application, but such a user interface widget is not part of the SDK, so I probably need to create one myself.

My idea is to have a background with marks and colored fields (green, yellow, red) as one bitmap, and the needle as another bitmap drawn on top of the background but rotated at an appropriate angle.

In my book "Professional Application Development for Android 2" there is a somewhat similar example with the growth of the compass, although this picture is drawn using linear graphics, and not ready-made images, as I should use to get the desired look.

However, in the compass example, the entire canvas rotates before drawing labels. I cannot use this approach, since it will also rotate the background of the track. So I need to somehow rotate the needle image (which should be transparent) before overlaying it. But I do not know how to do this.

Can someone lead me in the right direction, how to continue acupuncture? Also, if there is a better way to build a counter than the sketch above, please let me know.

+4
source share
1 answer

You can split your image into different layers. One for the background, one for the mark. The layer for tags can be rotated to draw tags, and then back and in combination with the background layer.

You can see the following example with the layer technology described above: http://mindtherobot.com/blog/534/android-ui-making-an-analog-rotary-knob/

PS This is not my blog, I just found this technique there.

+3
source

All Articles