您好我正在研究一個Android應用程序,其中涉及重繪畫布和同時啓動天文臺。任何人都知道這是如何實現的?從reDraw開始計時
我試圖在調用invalidate()時在View類中調用chronometer.start。但是,只有畫布被重新繪製,天文臺根本沒有啓動。
編輯: 這是我試過的代碼:
public class ReDraw extends View{
public ReDraw(Context context){
super(context);
this.selfPointer = this;
setFocusable(true);
chrono(context);
}
public void chrono(Context context){
chrono = new Chronometer(context);
chrono.setOnChronometerTickListener(new OnChronometerTickListener(){
public void onChronometerTick(Chronometer arg){
elapsedTime = (SystemClock.elapsedRealtime() - arg.getBase())/1000;
long milliseconds= (long) (elapsedTime/60);
String millisec=Long.toString(milliseconds);
arg.setText(millisec);
}
});
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
}
}
protected void onDraw(Canvas Square)
{
super.onDraw(Square);
Paint squareColor = new Paint();
squareColor.setColor(Color.BLACK);
Square.drawRect(200,100,200,100, squareColor);
return;
}
}
public boolean onTouchEvent(MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
invalidate();
}
return;
}
}
請發表您的代碼,以便我們可以很容易弄清楚? –
發佈了代碼! @MichaelShrestha – shannon