1

我有个问题。我有一个计时器,看起来像一个向后移动的进度条。现在它工作得很好,或者我应该说在旧手机上效果很好,但是带有高清屏幕的新手机却不能很好地工作。计时器栏在我的 xml 中设置为 vert 和 match_parent。我在下面包括了我的方法,你能看看它并告诉我如何改进它吗?

//used to animate timer bar
private Handler mHandler = new Handler();

//timer event code
private Runnable mUpdateTimeTask = new Runnable() {
       public void run() {
           final long start = startTime; 
// startTime will come from a spinner it will be 0,1,2,3,4 or 5 (users choice) 
// ** the bar is GREEN until the if condition is meet
           long currentLength = System.currentTimeMillis() - start;
           long remainingTime = gameTime - currentLength;
           float x = (float)remainingTime / (float)gameTime;

           if(remainingTime > 0)
           {
               //still have time remaining - update UI
               LinearLayout timerUI = (LinearLayout) findViewById(R.id.timerUI);
               timerUI.getLayoutParams().height =  (int) (x * 400);

               //update color
               if(remainingTime < 15000)
                  timerUI.setBackgroundColor(Color.RED);
               else if(remainingTime < 30000)
                   timerUI.setBackgroundColor(Color.YELLOW);

               timerUI.requestLayout();
               timerUI.invalidate();
               mHandler.postDelayed(this, 500);
           }
           else
           {
               if(monitorThread != null)
                   monitorThread.interrupt();

                //NEED to push user to final screen
                Intent resultsIntent = new Intent(SingleGameActivity.this, 
                    ResultsActivity.class);
                startActivity(resultsIntent);
           }
       }
    };
4

0 回答 0