2011-01-19 3 views
3

저는 안드로이드 개발을 처음 접했고 안드로이드의 기본 아날로그 시계에 "초침"을 추가 할 수 있는지 궁금합니다.안드로이드 시계 초침

나는 이미 다이얼, 시침 및 분침이 작동하는 시계가 있습니다. 나는 주변을 수색 해 왔으며 매 초마다 시계를 업데이트하기 위해 백그라운드에서 실행중인 서비스가 필요하다는 일부 게시물을 보았습니다. 그래도 시계 위젯 용이었고 광산은 앱 용이었습니다.

할 수있는 방법이 있습니까?

답변

1

은 그 방법은 다음과 같습니다 http://developer.android.com/resources/articles/timed-ui-updates.html

경고 : 정말 빨리 배터리를 소모합니다 그 일을!

+0

고마워, 그래서 기본 아날로그 시계에 이것을 적용 할 수 있는가? 여기에 예로 든 디지털 타이머가 있습니다. 그래, 내가 시계가 하하를 보여주는 동안 그것은 확실히 충전해야 할 일을 할 수있다. 다시 한 번 감사드립니다 – user581949

+0

나는 그들이 사용했던 예제가 시계라는 것을 알지조차 못했습니다. 당신이 묻는대로 UI를 매 순간 업데이트한다는 것을 알았습니다. –

+0

오, 고마워요. :) – user581949

0

시계를 시간과 분침으로 이미 렌더링 한 경우 초침의 문제점은 무엇입니까? 다른 손을 업데이트 할 때 정확히 업데이트하십시오. 업데이트 스레드의 빈도를 1 초로 늘리십시오.

0

네, 안드로이드 아날로그 시계에 중고품을 넣을 수 있습니다. 제 신청서에 여기에 언급 된 내용보다 오류가 있으면 도움을 받으십시오. 여기 링크 you can find it here in link

0
private ImageView img; 
Handler mHandler; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Thread myThread = null; 

    Runnable runnable = new CountDownRunner(); 
    myThread = new Thread(runnable); 
    myThread.start(); 

} 

public void doRotate() { 

    runOnUiThread(new Runnable() { 
    public void run() { 
    try { 

    Date dt = new Date(); 
    int hours = dt.getHours(); 
    int minutes = dt.getMinutes(); 
    int seconds = dt.getSeconds(); 
    String curTime = hours + ":" + minutes + "::" + seconds; 
    Log.v("log_tag", "Log is here Time is now" + curTime); 
    img = (ImageView) findViewById(R.id.imgsecond); 
    RotateAnimation rotateAnimation = new RotateAnimation(
     (seconds - 1) * 6, seconds * 6, 
     Animation.RELATIVE_TO_SELF, 0.5f, 
     Animation.RELATIVE_TO_SELF, 0.5f); 

    rotateAnimation.setInterpolator(new LinearInterpolator()); 
    rotateAnimation.setDuration(1000); 
    rotateAnimation.setFillAfter(true); 

    img.startAnimation(rotateAnimation); 
    } catch (Exception e) { 

    } 
    } 
    }); 
} 

class CountDownRunner implements Runnable { 
    // @Override 
    public void run() { 
    while (!Thread.currentThread().isInterrupted()) { 
    try { 

    doRotate(); 
    Thread.sleep(1000); 
    } catch (InterruptedException e) { 
    Thread.currentThread().interrupt(); 
    } catch (Exception e) { 
    Log.e("log_tag", "Error is " + e.toString()); 
    } 
    } 
    } 
}