2013年6月20日 星期四

[Android] 一閃一閃亮晶晶的BlinkLayout

Androids Do Daydream裡有提到Romain Guy要他提(大概假的吧)在layout裡面放"<blink>"可以做到view閃爍的效果而不用寫到一行code

查了一下AOSP的原始碼也的確有這東西, 它是一個躲在LayoutInflater的一個叫BlinkLayout的東西, 這樣一來就可以配合TextClock (API Level 17)來做一個閃爍的時鐘了

<blink android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textClock"
android:textSize="60sp"
android:textColor="#b3b5b5"/>
</blink>

不過, 這樣, 是整個TextClock在閃, 而不是像一般數字鐘一樣是只有":"閃, 如果要做到只有":"在閃, 那只好把"時"跟"分"給拆開, 像這樣:

<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textClock"
android:textSize="60sp"
android:textColor="#b3b5b5"
android:format24Hour="k"/>
<blink android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=":"
android:id="@+id/textView"
android:textSize="60sp"
android:textColor="#b3b5b5"/>
</blink>
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textClock2"
android:textSize="60sp"
android:textColor="#b3b5b5"
android:format24Hour="mm"/>

沒有留言:

張貼留言