闪亮亮的文本框效果
我已经相信有些人我永远不必等……当然这要除了送快递的——昨天买了许多IT书和文学小说。
大学里课程设计的时候做过数字钟,是用汇编语言写的,感觉那个闪亮的数字界面很好看,下面用代码实现一下那种显示界面。
主类中没什么东西,就不贴代码了,自定义了一个LedTextView类,设置特殊字体,也很简单:
packagecom.example.ledtextviewtest;importandroid.content.Context;importandroid.content.res.AssetManager;importandroid.graphics.Typeface;importandroid.util.AttributeSet;importandroid.widget.TextView;publicclassLedTextViewextendsTextView{publicLedTextView(Contextcontext,AttributeSetattrs){super(context,attrs);AssetManagerassetManager=context.getAssets();//设置某种样式的字体Typefacefont=Typeface.createFromAsset(assetManager,"digital-7.ttf");setTypeface(font);}}
最主要的是从asset文件夹中获取一种字体的样式,样式文件是下载的,我使用的是“digital-7.ttf”,如图:
XML文件:
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#000"><com.example.ledtextviewtest.LedTextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:text="88:88:88"android:textColor="#3300ff00"android:textSize="80sp"/><com.example.ledtextviewtest.LedTextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:shadowColor="#00ff00"android:shadowDx="0"android:shadowDy="0"android:shadowRadius="10"android:text="09:45:23"android:textColor="#00ff00"android:textSize="80sp"/></RelativeLayout>
有两个自定义的UI控件,其中第一个显示背景,第二个显示当前时间值。其中第一个LedTextView设置浅一些的颜色,第二个LedTextView的阴影和字体颜色设置相同,都是“#00ff00”。
android:shadowDx="0"和android:shadowDy="0"可以改变阴影与文本内容之间的偏移度,“0”则表示不偏移。android:shadowRadius="10"为阴影的半径,设置可以使文本看起来更亮些。
效果图:
我只是写了一个文本的效果,可以把它真正做成一个电子时钟。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。