本文介绍了如何使文本视图闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们,我有一个需要它闪烁的文本视图,请帮助我.
Guys i have a textview which i need it to be blinking please help me with it.
<TextView
android:id="@+id/usage"
android:layout_marginTop="220dip"
android:layout_marginLeft="45dip"
android:layout_marginRight="15dip"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Google "
android:textColor="#030900"/>
我希望谷歌文字闪烁
推荐答案
已编辑
在 3.0
蜂窝版之前,这是对 Android 的弃用答案,请使用 SolArabehety 的回答 或查看这个线程.
Edited
It is a deprecated answer to Android before version 3.0
honeycomb, please uses SolArabehety's answer or look at this thread.
我保留这个答案的唯一原因是android 3.0之前Android动画有很多问题的历史原因,这个糟糕"解决方案在当时有效,现在使用它是不可想象的,所以只是去寻找动画解决方案,不要使用此代码.
The only reason I keep this answer is to historical reasons before android 3.0 Android animations had a lot of problems, this "bad" solution work at that time, nowadays it is unthinkable to use it, so just go for an animation solution, don't use this code.
package teste.blink;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
public class TesteBlinkActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
blink();
}
private void blink(){
final Handler handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
int timeToBlink = 1000; //in milissegunds
try{Thread.sleep(timeToBlink);}catch (Exception e) {}
handler.post(new Runnable() {
@Override
public void run() {
TextView txt = (TextView) findViewById(R.id.usage);
if(txt.getVisibility() == View.VISIBLE){
txt.setVisibility(View.INVISIBLE);
}else{
txt.setVisibility(View.VISIBLE);
}
blink();
}
});
}
}).start();
}
<TextView
android:id="@+id/usage"
android:layout_marginTop="220dip"
android:layout_marginLeft="45dip"
android:layout_marginRight="15dip"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Google "
android:textColor="#030900"/>
这篇关于如何使文本视图闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!