android中的字体闪烁效果和跑马灯效果

android中的字体闪烁效果和跑马灯效果_第1张图片

代码:MainActivity   

package com.wsj.textviewdmeo;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.widget.TextView;

public class MainActivity extends Activity {

	private TextView tv_text;
	private int clo = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		tv_text = (TextView) findViewById(R.id.tv_text);
		shark();
	}

	private void shark() {
		Timer timer = new Timer();
		TimerTask taskcc = new TimerTask() {
			public void run() {
				runOnUiThread(new Runnable() {
					public void run() {
						if (clo == 0) {
							clo = 1;
							tv_text.setTextColor(Color.TRANSPARENT);
						} else {
							if (clo == 1) {

								clo = 2;
								tv_text.setTextColor(Color.YELLOW);
							} else if (clo == 2) {

								clo = 3;
								tv_text.setTextColor(Color.RED);

							} else {
								clo = 0;
								tv_text.setTextColor(Color.BLUE);
							}
						}
					}
				});
			}
		};
		timer.schedule(taskcc, 1, 100);  //第二个参数分别是delay(多长时间后执行),第三个参数是:duration(执行间隔)单位为:ms
	}
}

跑马灯效果:需要在TextView中设置宽度  当文本超过宽度的时候跑马灯

 

你可能感兴趣的:(Android)