4

I need a graphical needle gauge (like a speedometer etc) for my app but such a UI widget is not part of the SDK so I probably have to create it myself.

My idea is to have the background with the tickmarks and coloured fields (green, yellow, red) as one bitmap and the needle as another bitmap drawn on top of the background, but rotated in the appropriate angle.

In my book, Professional Android 2 Application Development, there is a somewhat similar example with a compass rose, although that one is drawn using line graphics, not pre-fabricated images like I will have to use to get the desired look.

However, in the compass example the whole canvas is rotated before drawing the tick marks. I cannot use this approach as it will also rotate the gauge background. So I need to somehow rotate the needle image (which should be transparent) before superimposing it. But I don't know how to do accomplish this.

Can anyone lead me in the right direction on how to proceed with the needle gauge? Also, if there is a better way to build the meter than sketched above, please let me know.

4

1 回答 1

3

你可以把你的量表分成不同的层。一个用于背景,一个用于刻度线。刻度线图层可以旋转以绘制标记,并在转回并与“背景”图层组合时。

您可以使用上述层技术查看以下示例:http: //mindtherobot.com/blog/534/android-ui-making-an-analog-rotary-knob/

PS 这不是我的博客,我只是在那里发现了这种技术。

于 2011-05-24T20:20:03.800 回答