Android學習筆記_S01_E02 AnalogClock和DigitalClock(時鐘)的功能和用法

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   ar   color   os   使用   

一、基本定義

  AnalogClock和DigitalClock是兩個非常簡單的組件,而DigitalClock本身就是文字框,只是它裡面顯示的內容是時間,但DigitalClock的android:text屬性沒什麼作用。而AnalogClock則繼承了View組件,重寫了View的OnDraw方法,在View上繪製類比時鐘。

二、屬性

   AnalogClock支援的XML屬性的說明。

XML屬性 說明
android:dial 設定該類比時鐘的錶盤使用的圖片
android:hand_hour 設定該類比時鐘的時針錶盤使用的圖片
android:hand_minute 設定該類比時鐘的分針使用的圖片
三、實現效果四、編寫過程

  AnalogClock和DigitalClock的編寫比較簡單,只需要在XML檔案中放入相應的控制項的即可,在根據屬性引用相關圖片。

  1、在XML檔案中建立DigitalClock控制項。

1 <DigitalClock 2         android:id="@+id/digitalClock"3         android:layout_width="wrap_content"4         android:layout_height="wrap_content"5         android:textSize="30sp"6         android:isScrollContainer="true"/>
View Code

  2、建立AnalogClock控制項。dial屬性控製表盤樣式,通過“@Drawable/圖片"找到;hand_hour和minute控制指標樣式,通過"@Drawable/圖片"找到。

1 <AnalogClock 2         android:id="@+id/analogClock"3         android:layout_width="wrap_content"4         android:layout_height="wrap_content"5         android:dial="@drawable/watch"6         android:hand_hour="@drawable/hand"7         android:hand_minute="@drawable/hand"/>
View Code 五、原始碼

  xml檔案,其他代碼不用變

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="vertical" 6     tools:context=".MainActivity" > 7  8     <DigitalClock  9         android:id="@+id/digitalClock"10         android:layout_width="wrap_content"11         android:layout_height="wrap_content"12         android:textSize="30sp"13         android:isScrollContainer="true"/>14     15     <AnalogClock 16         android:id="@+id/analogClock"17         android:layout_width="wrap_content"18         android:layout_height="wrap_content"19         android:dial="@drawable/watch"20         android:hand_hour="@drawable/hand"21         android:hand_minute="@drawable/hand"/>22 23 </LinearLayout>
View Code 

Android學習筆記_S01_E02 AnalogClock和DigitalClock(時鐘)的功能和用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.