2014-09-21 51 views
0

我在eclipse中为android制作秒表。我正在使用天文钟,我想知道如何显示毫秒。这是我的代码的样子。 P.S:我是一个初学者,所以这可能听起来愚蠢到你:P在天文台显示毫秒

 Button startChrono; 
Button pauseChrono; 
Chronometer chrono; 
long time = 0; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    startChrono = (Button) findViewById(R.id.button1); 
    pauseChrono = (Button) findViewById(R.id.button2); 
    chrono = (Chronometer) findViewById(R.id.chronometer1); 
    startChrono.setOnClickListener(this); 
    pauseChrono.setOnClickListener(this); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

@Override 
public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    switch (arg0.getId()) { 
    case R.id.button1: 
     chrono.setBase(SystemClock.elapsedRealtime() + time); 
     chrono.start(); 
     break; 

    case R.id.button2: 
     time = chrono.getBase() - SystemClock.elapsedRealtime(); 
     chrono.stop(); 
     break; 
    } 
} 

回答

0

我不认为这是可能的天文台表。它只支持细粒度的时间分辨率至秒。另外,看代码后,我看到他们在做这个:

private Handler mHandler = new Handler() { 
    public void More ...handleMessage(Message m) { 
     if (mRunning) { 
      updateText(SystemClock.elapsedRealtime()); 
      dispatchChronometerTick(); 
      sendMessageDelayed(Message.obtain(this, TICK_WHAT), 1000); 
     } 
    } 
}; 

看起来是故意的,它目前每秒更新一次。这是可以理解的,因为这个组件是一个TextView,当文本改变时(如果layout_width是wrap_parent,通常会导致它的父级重新布局)。

您必须寻找替代解决方案才能获得细节和更新你想要的表现。