国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)LED發(fā)光字效果

2019-10-22 18:13:43
字體:
供稿:網(wǎng)友

大家好,這一篇博客來教大家一個(gè)類似于LED鬧鐘顯示屏樣式的小案例,UI比較美觀,文末會(huì)提供下載相關(guān)資源地址供大家下載,首先我們來看一看這個(gè)案例的運(yùn)行效果。

Android,發(fā)光字,LED發(fā)光字,LED發(fā)光字效果

正常運(yùn)行在手機(jī)中時(shí),效果很流暢,gif上可能是由于錄制完轉(zhuǎn)碼的時(shí)候,速度調(diào)快了,所以看上去速度比較快,這都是小事情,接下來我們來看看源碼是如何實(shí)現(xiàn)的。

1.代碼很簡(jiǎn)單,主要是利用xml布局文件的幾個(gè)屬性,并且通過設(shè)置我們特定的字體就能很容易的實(shí)現(xiàn)我們看到的效果啦,首先我們創(chuàng)建一個(gè)類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); }}

這里我們?cè)O(shè)置了我們特定的字體樣式digital-7.ttf。

2.下面我們看看布局文件是如何寫的

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="#000000" android:layout_height="match_parent"> <com.eloancn.ledtextview.LedTextView  android:layout_centerInParent="true"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_gravity="center"  android:text="88:88:88"  android:textColor="#3300ff00"  android:textSize="80sp" /> <com.eloancn.ledtextview.LedTextView  android:layout_centerInParent="true"  android:id="@+id/main_clock_time"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_gravity="center"  android:shadowColor="#00ff00"  android:shadowDx="0"  android:shadowDy="0"  android:shadowRadius="10"  android:textColor="#00ff00"  android:textSize="80sp" /></RelativeLayout>

可以看到,我們主要是在上面一層的TextView控件上設(shè)置了以下幾個(gè)屬性

android:shadowColor="#00ff00"android:shadowDx="0"android:shadowDy="0"android:shadowRadius="10"

并且設(shè)置了指定的顏色,這樣就能實(shí)現(xiàn)LED發(fā)光字的效果。

3.下面我們?cè)賮砜纯碝ainActivity是如何實(shí)現(xiàn)的,代碼很簡(jiǎn)單,主要是獲取當(dāng)前時(shí)間,分別截取時(shí)分秒賦給我們的textView。

public class MainActivity extends AppCompatActivity { private static final String DATE_FORMAT = "%02d:%02d:%02d"; private static final int REFRESH_DELAY = 500; private final Handler mHandler = new Handler(); private final Runnable mTimeRefresher = new Runnable() {  @Override  public void run() {   final Date d = new Date();   mTextView.setText(String.format(DATE_FORMAT, d.getHours(),     d.getMinutes(), d.getSeconds()));   mHandler.postDelayed(this, REFRESH_DELAY);  } }; private TextView mTextView; @Override public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.activity_main);  mTextView = (TextView) findViewById(R.id.main_clock_time); } @Override protected void onResume() {  super.onResume();  mHandler.post(mTimeRefresher); } @Override protected void onStop() {  super.onStop();  mHandler.removeCallbacks(mTimeRefresher); }}

怎么樣,代碼是不是很簡(jiǎn)單就實(shí)現(xiàn)了呢,大家趕快試一試吧!

字體資源下載地址:Android實(shí)現(xiàn)LED發(fā)光字效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 青神县| 鞍山市| 九江县| 玛纳斯县| 隆德县| 丰城市| 芮城县| 嘉义市| 西乡县| 陈巴尔虎旗| 镇巴县| 弋阳县| 东方市| 甘南县| 越西县| 津南区| 磐安县| 鄢陵县| 衡东县| 会东县| 巧家县| 广南县| 太康县| 临朐县| 岚皋县| 西峡县| 文安县| 洱源县| 石狮市| 滦平县| 错那县| 天台县| 镇康县| 库伦旗| 合阳县| 堆龙德庆县| 根河市| 伊通| 仁布县| 博白县| 巢湖市|