1

How can create a View like this

enter image description here

In the quiz game, each level, this View will countdown the time, the faster the answer is chosen, the higher score will be. So, the first thing is how to get the time on this View.

Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116
  • 1
    should be easy enough. Find or design the alarm clock as a png and create an image view as its source to display it. Create a Text view for the seconds and get a nice font for it. - http://www.fontsquirrel.com/ -- You put the textview inside something like a frame layout so you can position it in the center of the alarm clock, and use a countdown timer to change the textviews text, seconds - http://stackoverflow.com/questions/10032003/how-to-make-a-countdown-timer-in-android - how to change a textviews font using Typeface -- http://stackoverflow.com/questions/12553727/change-textview-font – Tasos Sep 20 '15 at 06:49
  • I got it, thank you. – Twitter khuong291 Sep 20 '15 at 06:55

1 Answers1

6

Create a layout for your alarm drawable, including an ImageView and a TextView that overlays on it.

Initialize your objects before onCreate():

CountDownTimer countDownTimer;
TextView tvTime;

Then create a method and add this to it, or add it to onCreate():

countDownTimer = new CountDownTimer(60000, 1000) {
    @Override
    public void onTick(long millisUntilFinished) {
        tvTime.setText(String.valueOf((int) millisUntilFinished / 1000));
    }

    @Override
    public void onFinish() {
        endGame(); //End the game or do whatever you want.
    }
}.start();

where 60000 is the total countdown time in milliseconds and 1000 is the time interval for onTick in milliseconds.

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57