我想在android studio中为android应用程序创建一个动态雷达,看起来像这样:
http://jsbin.com/AMag/2/edit?html,css,output
我怎么能这样做?
答案 0 :(得分:0)
这是一个起点。像这样创建一个自定义视图并将其添加到LinearLayout。
class RadarBlip {
float x;
float y;
public void setX (float x) {
this.x = x;
}
public Float getX() {
return x;
}
....
}
private class RadarView extends View {
List<RadarBlip> mRadarBlips;
public TimerViewContentView(Context context, List<RadarBlip> radarBlips, currentRadarAngle) {
super(context);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mRadarBlips = radarBlips;
}
@Override
protected void onDraw(Canvas canvas) {
for(int i = 0; i < mRadarBlips.size(); i++) {
blipPaint.setAlpha(...do geometry...);
canvas.drawCircle(mRadarBlips.get(i).getX(), mRadarBlips.get(i).getY(), radius, blipPaint);
}
canvas.drawArc(oval, currentRadarAngle, currentRadarAngle - 10, false, radarPaint);
}
}
然后,您想要在Timer中调用视图。类似的东西:
new CountDownTimer(timeRemaining, 15) {
public void onTick(long millisUntilFinished) {
float radarAngle = ((long)millisUntilFinished)%((long)timeForRevolution) * 360f;
RadarView mRadarView = new RadarView(MyActivity.this,radarPointsArray,radarAngle);
radarLayout.removeAllViewsInLayout();
radarTimerLayout.addView(mRadarView);
timeRemaining = millisUntilFinished;
}
public void onFinish() {
}
}.start();
考虑使用NineOldAndroids的ObjectAnimator而不是Timer可能会更好。虽然ObjectAnimator倾向于永远不会停止和耗尽电池,除非你添加一个功能来阻止它。