android跑马灯效果
来源:互联网 发布:网络服务器虚拟化 编辑:程序博客网 时间:2024/04/29 15:25
public class ScrollingText extends Activity
{
public TextView t1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t1= (TextView) findViewById(R.id.t1);
t1.setText("089289599298929682968“);
t1.setTextSize(30);
t1.setHorizontallyScrolling(true);
t1.setFocusable(true);
}
}
在这段程序中我设置了t1的焦点为真(意思为焦点在t1上),我设置了t1的文本显示能超过其显示区域(t1.setHorizontallyScrolling(true) 设置的这行的目的是为了不让程序自动给文本折行,使之为单行),当然这些属性你都可以在XML文件中定义。接下来我们看看main.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget35"
android:layout_;fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/black"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/t1"
android:layout_width="100px"//此处为文本显示区域的宽度此值必须比你的文本宽度要小否则是没有效果的
android:layout_height="wrap_content"
android:text="@string/str_id"
android:textColor="@drawable/green"
android:layout_x="61px"
android:layout_y="69px"
android:scrollX="2px"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
>
</TextView>
<ViewStub android:layout_y="221dip" android:layout_;wrap_content" android:layout_x="103dip" android:id="@+id/ViewStub01" android:layout_height="wrap_content"></ViewStub>
</AbsoluteLayout>
其中singleLine表示TextView中文本为单行文本如果你在你的程序中设置了setHorizontallyScrolling(true)在这你可以不写了,接下来就是我们的关键之处了ellipsize="marquee" 此语句表示我们将TextView设置为了一个走马灯,marqueeRepeatLimit="marquee_forever" 表示走马灯的滚动效果重复的次数,你可以填一个自然数。
好了接下了编译试试。
闪烁文字的制作
private boolean change = false;
TextView touchScreen = (TextView)findViewById(R.id.touchscreen);//获取页面textview对象
Timer timer = new Timer();
timer.schedule(task,1,300); //参数分别是delay(多长时间后执行),duration(执行间隔)
TimerTask task = new TimerTask(){
public void run() {
runOnUiThread(new Runnable(){
public void run() {
if(change){
change = false;
touchScreen.setTextColor(Color.TRANSPARENT); //这个是透明,=看不到文字
}else{
change = true;
touchScreen.setTextColor(Color.RED);
}
}});
}
};
- Android 跑马灯效果
- android跑马灯效果
- android跑马灯效果
- Android跑马灯效果
- Android 跑马灯效果
- android跑马灯效果
- android 跑马灯效果
- Android跑马灯效果
- android 跑马灯效果
- android 跑马灯效果
- Android跑马灯效果
- android 跑马灯效果
- Android 跑马灯效果
- Android跑马灯效果
- android 跑马灯效果
- Android跑马灯效果
- android跑马灯效果
- android 跑马灯效果
- 无穷级数
- 计算机组成-高速缓冲存储器Cache
- vi/emacs 搜索文件中的特定字符串
- Bat字符串处理函数
- Implementing Repository Pattern With Entity Framework
- android跑马灯效果
- 可计算性、可判定性和可满足性
- android横竖屏切换时候Activity的生命周期
- 《新贫富标准》
- 关于触发器问题
- 用内部类实现接口
- CentOS 6.0 配置 tftp-server
- 三大范式
- 最近很懒