我如何显示这样的时钟

发布于 2024-09-07 07:07:13 字数 486 浏览 8 评论 0原文

我打算以这种方式显示时钟

替代文字

我已经完成了时钟..并且我不知道如何获得像上图这样的小文本“PM”。

也适用于星期一星期二星期三......

Calendar c = new GregorianCalendar();

 if(c.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY){
    System.out.println("MON");
} else if (c.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY){
        System.out.println("TUE");
}

等等。

I intend to show the clock in this way

alt text

I've done for the clock .. and I'm not sure how to get the small text "PM" like pic above.

also for the MON TUE WED ....

Calendar c = new GregorianCalendar();

 if(c.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY){
    System.out.println("MON");
} else if (c.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY){
        System.out.println("TUE");
}

and so forth .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千と千尋 2024-09-14 07:07:13

AM/PM 指示器应该只是一个单独的 TextView,位于布局中适当的位置,具有较小的 android:textSize。至少,我会这么做。

如果我误解了你的问题,我很抱歉,但很难确定你所说的“最小化文本”是什么意思。

The AM/PM indicator should just be a separate TextView, in an appropriate position in the layout, with a smaller android:textSize. At least, that is how I would do it.

If I misunderstood your question, I apologize, but it is difficult to determine what you mean by "minimize the text".

怀念你的温柔 2024-09-14 07:07:13
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());
    }
   }
  }
 }
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());
    }
   }
  }
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文