十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊
量身定制 + 運營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
大家好,這一篇博客來教大家一個類似于LED鬧鐘顯示屏樣式的小案例,UI比較美觀,文末會提供下載相關(guān)資源地址供大家下載,首先我們來看一看這個案例的運行效果。
正常運行在手機(jī)中時,效果很流暢,gif上可能是由于錄制完轉(zhuǎn)碼的時候,速度調(diào)快了,所以看上去速度比較快,這都是小事情,接下來我們來看看源碼是如何實現(xiàn)的。
1.代碼很簡單,主要是利用xml布局文件的幾個屬性,并且通過設(shè)置我們特定的字體就能很容易的實現(xiàn)我們看到的效果啦,首先我們創(chuàng)建一個類LedTextView繼承自TextView。
public class LedTextView extends TextView { private static final String FONTS_FOLDER = "fonts"; private static final String FONT_DIGITAL_7 = FONTS_FOLDER + File.separator + "digital-7.ttf"; public LedTextView(Context context) { super(context); init(context); } public LedTextView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public LedTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); } private void init(Context context) { AssetManager assets = context.getAssets(); final Typeface font = Typeface.createFromAsset(assets, FONT_DIGITAL_7); setTypeface(font); } }