반응형

안드로이드 스튜디오(Android Studio)에서 시계에 대한 예제 중 가장 유명한 것이 바로 TimePicker다. 아래의 사진을 보자.

 

안드로이드 스튜디오(Android Studio)로 App 개발을 하게 되면, 시계에 관한 가장 대표적인 예가 TimePicker로 사용을 한다. 여기서, spinner 방식과 clock 방식이 있다.

 

위의 사진에서 상단은 spinner 방식이고, 아래 시계에 대한 것은 clock 방식이다.

 

아래 코드를 보면, android:timePickerMode가 spinner냐 clock이냐에 따라서 모양이 달라진다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:padding="20dp">

    <TimePicker
        android:id="@+id/time_picker_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:timePickerMode="spinner" />

    <TimePicker
        android:id="@+id/time_picker_clock"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:timePickerMode="clock" />
</LinearLayout>

 

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기